0

为什么这个方法从不调用?谁能帮我检查我的代码,我是新手。

这是我的 *.h 文件

@interface LoginViewController : UIViewController <FBSessionDelegate,FBRequestDelegate,FBDialogDelegate> {

    Facebook *facebook;
    IBOutlet UITextField *_txt;
    NSString *facebookUserID;

我想获取 faceboo 用户 ID,所以我调用了 API '[facebook requestWithGraphPath:@"me" andDelegate:self];'

- (void) fbDidLogin
{
    NSLog(@"[LOGIN] Used did login");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    // User has logged in to Facebook, now get their userId from Facebook 
    [facebook requestWithGraphPath:@"me" andDelegate:self];     
}

我知道下面的方法会获取用户 ID,但它从未调用过。

- (void)request:(FBRequest *)request didLoad:(id)result 
{
    NSLog(@"Inside didLoad");     
    if ([result isKindOfClass:[NSArray class]])
    {
        result = [result objectAtIndex:0];
    }
    // When we ask for user infor this will happen.
    if ([result isKindOfClass:[NSDictionary class]])
    {
        //NSDictionary *hash = result;         
        NSLog(@"Name: %@", [result objectForKey:@"name"]);

        self.facebookUserID = [result objectForKey:@"id"];
        NSLog(@"ID: %@", [result objectForKey:@"id"]);
    }
}
4

1 回答 1

0

您需要实现 openURL 或 handleOpenURL(后者在 ios 4.2 之前)。它需要在您的应用程序委托中实现,而不是您的视图控制器。

请参阅未调用 fbDidLogin。openURL 将导致 fbDidLogin 被调用

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    NSLog(@"============HANDLE OPEN URL");
    ViewController *v =(ViewController *) vc;
    return [[v facebook] handleOpenURL:url]; 
}
于 2012-06-05T14:02:14.767 回答