我正在尝试将 facebook iOS SDK 集成到我的应用程序中,在我的应用程序委托标头中,我执行以下操作:
#import <UIKit/UIKit.h>
#import "Facebook.h"
#import "FBConnect.h"
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
Facebook *facebook;
}
@property (nonatomic,strong) Facebook *facebook;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
并在实现文件的方法 didFinishLaunchingWithOptions 方法中:
MyFacebooDelegate *controllerDelegate = [[MyFacebooDelegate alloc] init];
facebook = [[Facebook alloc] initWithAppId:appID andDelegate:controllerDelegate];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
if([userDefault objectForKey:@"FBAccessTokenKey"] && [userDefault objectForKey:@"FBExpirationDateKey"])
{
facebook.accessToken = [userDefault objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [userDefault objectForKey:@"FBExpirationDateKey"];
}
if(![facebook isSessionValid])
{
NSArray *permision = [[NSArray alloc]initWithObjects:@"read_stream",nil] ;
[facebook authorize:permision];
}
MyFacebooDelegate 类是我实现 Facebook 代表(如 FBSessionDelegate 等)的地方。
我也处理了 handleOpenURL 和 OpenURL,当我运行应用程序时,我在 safari 中获得了 facebook 身份验证屏幕,然后按“确定”屏幕被关闭并返回到我的应用程序,但有时应用程序崩溃并退出,这里是编译器告诉我错误:
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate {
self.accessToken = token;
self.expirationDate = expirationDate;
[_lastAccessTokenUpdate release];
_lastAccessTokenUpdate = [[NSDate date] retain];
[self reloadFrictionlessRecipientCache];
if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)]) {
[self.sessionDelegate fbDidLogin];
}
特别是编译器指出这一行:
if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)]) {
任何帮助将不胜感激