如果facebook应用程序安装在iphone中或未安装,我想制作一个应用程序,要求在对话框中验证facebook登录。如果我注销facebook,那么它应该从facebook注销。我已将 facebook-ios-sdk 用于 facebook api 我的代码如下:
- (void)viewDidLoad
{
_facebook=[[Facebook alloc] initWithAppId:appId andDelegate:self];
self.navigationController.navigationBarHidden = YES;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
{
_facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
_facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
[super viewDidLoad];
}
//点击登录按钮
-(IBAction)Login
{
NSLog(@"login called");
if (![self connected])
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Connection" message:@"Internet is not Connected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];[alert release];
}
else
{
if (suggestion==nil)
{
suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
}
[suggestion setReqFlg:YES];
if (![_facebook isSessionValid])
{
NSLog(@"sesssion invalid u have to login...");
[_facebook authorize:nil];
}
else
{
NSLog(@"valid and going on next page called graph API ");
[_facebook requestWithGraphPath:@"me?fields=id,name" andDelegate:self];
suggestion.parentView=self;
[self.navigationController pushViewController:suggestion animated:YES];
}
}
}
- (void)fbDidLogin
{
NSLog(@"facebook did first login..");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSLog(@"called gtraph from login in facebook ");
[_facebook requestWithGraphPath:@"me?fields=id" andDelegate:self];
if (suggestion==nil)
{
suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
}
suggestion.parentView=self;
[self.navigationController pushViewController:suggestion animated:YES];
}
- (void)fbDidLogout
{
NSLog(@"logout");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults removeObjectForKey:@"FBUserId"];
[defaults synchronize];
}
我是否必须更改 facebook.m 文件或有另一种方法可以做到这一点。每次我单击登录按钮时,如果 facebook 注销,则应显示 facebook 登录对话框,如果 facebook 登录,则导航到下一个视图。不要打开 facebook 应用程序安装在 iphone 中用于登录目的。
给你的评论或答案我真的需要它。谢谢你!