gpt4 book ai didi

iphone - 打开 facebook 对话框进行身份验证而不是在 iphone 中安装 facebook 应用程序?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:28 24 4
gpt4 key购买 nike

我想制作一个应用程序,无论是在 iphone 中安装还是未安装 facebook 应用程序,都要求在对话框中对 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 已登录,则应导航到下一个 View 。不要打开安装在 iphone 中的 facebook 应用程序以进行登录。

提供您的评论或答案我真的需要它。谢谢你!

最佳答案

进入 facebook.m 文件非常简单,使用 FBAppAuth 搜索,您会得到 3_4 个结果,例如:-

 [self authorizeWithFBAppAuth:YES safariAuth:YES];

只需将 YES 更改为 NO,例如:-

 [self authorizeWithFBAppAuth:NO safariAuth:NO];

仅在 facebook.m 中更改它并编译并运行当您单击 loginButton 时会出现 fblogin 对话框 :)

编辑

我的应用程序登录页面上有我的登录对话框

facebook login dialog

关于iphone - 打开 facebook 对话框进行身份验证而不是在 iphone 中安装 facebook 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11244555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com