使用iPhone上的图形API检查用户是否使用Facebook登录

时间:2012-07-11 05:02:25

标签: iphone facebook

我正在使用适用于iPhone的Facebook图形API制作反馈表。当用户提供反馈时,我们想要检查用户是否已经登录Facebook。

请任何人都可以提供帮助。

- (IBAction)submit:(id)sender {
    // This button pressed method check that user is already login or not 
}

请帮忙。谢谢!

1 个答案:

答案 0 :(得分:0)

您可以通过在Appdelegate.m文件中编写以下代码来检查fb会话:

 - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        /*
         Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
         */
        [self performSelector:@selector(checkingFBsession) withObject:nil afterDelay:1.0];

    }

-(void)checkingFBsession
{
   self.successfb= [[self facebook] isSessionValid];
    NSString *str = [[NSUserDefaults standardUserDefaults]objectForKey:@"access_token"];
    [str retain];
    NSLog(@"%@",str);
    if (self.successfb || str) {
        NSLog(@"session is valid !");

        accessToken=self.facebook.accessToken;
        [[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:@"access_token"];
        [[NSUserDefaults standardUserDefaults]synchronize];

        accessToken = nil;
        accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
      [accessToken retain];
        NSLog(@"at%@",accessToken);
        NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
        [request setDelegate:self];
        [request addPostValue:[[NSUserDefaults standardUserDefaults]objectForKey:@"access_token"] forKey:@"access_token"];

        //    [request addPostValue:@"123456" forKey:@"telephone"];
        [request startAsynchronous];
        }


}