我一步一步跟着Facebook上的Facebook SDK教程。除了fbDidLogin被调用之外,我还有一些工作...授权过程正常工作。有人告诉我做:IOS - Facebook SDK fbDidLogin未调用 - 初始化视图控制器。
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[controller facebook] handleOpenURL:url];
}
问题是,我不完全知道如何初始化页头我的视图控制器。这里是我的应用程序的委托.H:
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface fb2AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
Facebook *facebook;
UIViewController *fb2ViewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) Facebook *facebook;
@property (nonatomic, strong) UIViewController *fb2ViewController;
@end
与.m:
#import "fb2AppDelegate.h"
@implementation fb2AppDelegate
@synthesize window = _window;
@synthesize facebook;
@synthesize fb2ViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.fb2ViewController = [[UIViewController alloc] init];
facebook = [[Facebook alloc] initWithAppId:@"key_here" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[fb2ViewController facebook] handleOpenURL:url];
}
- (void)fbDidLogin {
NSLog(@"fbdidlogin");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"key_here", @"app_id",
@"http://developers.facebook.com/docs/reference/dialogs/", @"link",
@"http://fbrell.com/f8.jpg", @"picture",
@"Facebook Dialogs", @"name",
@"Reference Documentation", @"caption",
@"Using Dialogs to interact with users.", @"description",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
作为视图控制器...我还没有把任何代码在其中。
,我收到的错误是:
为“UIViewController的”没有明显的@interface声明选择“Facebook的
我到底做错了什么?
thx!
你是什么意思的第二个版本的实施? – stackOverFlew 2012-08-19 05:42:32
虽然...不起作用,但...给出以下错误: 不可见@interface for'UIViewController'声明选择器'Facebook'=( – stackOverFlew 2012-08-19 05:50:00
[iphone SSO Facebook实现]的可能重复(http:// stackoverflow .com/questions/10403697/iphone-sso-facebook-implementation) – CodaFi 2012-08-19 05:51:55