我一步一步地按照 Facebook 的 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
还有他们 :
#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”
我究竟做错了什么?
谢谢!