我正在使用 iPhone 的 Facebook 图形 API 制作反馈表。当用户给出反馈时,我们想检查用户是否已经登录 Facebook。
请任何人都可以提供帮助。
- (IBAction)submit:(id)sender {
// This button pressed method check that user is already login or not
}
请帮忙。谢谢!
您可以通过在 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];
}
}