gpt4 book ai didi

iOS : Login with Facebook and open Native Facebook app

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:48 25 4
gpt4 key购买 nike

  • 我想在登录时打开已安装在设备中用于登录身份验证的 facebook 应用程序,但始终在 Safari 浏览器中打开。

- facebook 按钮点击

    -(void)loginButtonClicked
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

// [login setLoginBehavior:FBSDKLoginBehaviorNative];

[login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(@"Login process error");
}
else if (result.isCancelled)
{
NSLog(@"User cancelled login");
}
else
{
NSLog(@"Login Success");
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"result is:%@",result);
[self fetchUserInfo];
}
else
{
// [SVProgressHUD showErrorWithStatus:@"Facebook email permission error"];
}
}
}];
}
}

-此处获取用户信息

        -(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"results:%@",result);

NSString *email = [result objectForKey:@"email"];
NSString *userId = [result objectForKey:@"id"];

if (email.length >0 )
{
NSString *accessToken = [[FBSDKAccessToken currentAccessToken] tokenString];
[ref authWithOAuthProvider:@"facebook" token:accessToken
withCompletionBlock:^(NSError *error, FAuthData *authData)
{
if (error)
{
NSLog(@"Login failed. %@", error);
}
else
{
NSLog(@"Logged in! %@", authData);

//Start you app Todo
}
else
{
NSLog(@"Facebook email is not verified");
}
}
else
{
NSLog(@"Error %@",error);
}
}];

}
  • 我想打开 facebook 应用程序以使用 facebook 登录。

最佳答案

从 V4.6.0 开始,它不会重定向到 fb 应用程序。见下文

(v4.6.0 - September 10, 2015) In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari. Follow the our Preparing for iOS 9 guide.

enter image description here

关于iOS : Login with Facebook and open Native Facebook app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37272684/

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