Facebook API“协议中的方法未实现”

时间:2012-03-24 10:43:20

标签: iphone ios xcode facebook api

我在我的AppDelegate

中做了
@interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
Facebook *facebook;
}

并按照Facebook Developers上的教程进行操作。但它仍然做了四次:

1)此处声明的方法(Facebook.h):

- (void)fbDidNotLogin:(BOOL)cancelled;

2)直接或间接协议“FBSessionDelegate”(AppDelegate.h)所需:

@interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
Facebook *facebook;
}

我忘记了吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

当您的AppDelegate声明遵循FBSessionDelegate协议时,它需要实现此协议中所有必需的方法。

所以你需要在AppDelegate.m中实现fbDidNotLogin方法,如

- (void)fbDidNotLogin:(BOOL)cancelled {
    // Do something here
}

答案 1 :(得分:0)

根据Hackbook示例,您必须添加更多方法:

- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
    [defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
    [defaults synchronize];}

    -(void)fbDidNotLogin:(BOOL)cancelled{
    }

    -(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt{

    NSLog(@"token extended");
    [self storeAuthData:accessToken expiresAt:expiresAt];
}

- (void)fbSessionInvalidated {
    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Auth Exception"
                              message:@"Your session has expired."
                              delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil,
                              nil];
    [alertView show];
    [alertView release];
    [self fbDidLogout];
}