FBSDKLoginManager无法在本机ios应用程序中打开登录对话框

Hiren kanetiya

我是新iPhone的发展,我想使用最新的Facebook SDK 4.一些我的家乡的iOS简单的应用程序做一个Facebook登录,我只是想打开一个网站登录对话框从自定义UIButton点击,我的应用程序,并为我做以下我的按钮单击方法中的代码。

- (IBAction)didTapLoginFaceBook:(id)sender {

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error

        NSLog(@"Unexpected login error: %@", error);
        NSString *alertMessage = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was a problem logging in. Please try again later.";
        NSString *alertTitle = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops";
        [[[UIAlertView alloc] initWithTitle:alertTitle
                                        message:alertMessage
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];


        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
            }
        }
    }];


}

这段代码的工作方式有所不同,但是我想UIButton在本机iOS应用程序中打开“自定义单击”的登录对话框

因此,请通过一些代码提出正确的建议,谢谢

阿什什·卡卡德(Ashish kakkad)

使用Objective-C中的自定义按钮的Facebook登录4.x

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    login.loginBehavior = FBSDKLoginBehaviorBrowser;
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 [self fetchUserInfo];
                 [login logOut];
             }
         }
     }];
}

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

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);

             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];
    }
}

使用Swift中的自定义按钮的Facebook登录4.x

@IBAction func btnFacebookPressed(_ sender: Any) {

    let loginManager = FBSDKLoginManager()
    loginManager.loginBehavior = FBSDKLoginBehavior.browser;

    loginManager.logIn(withReadPermissions: ["email"], from: self, handler: {(result : FBSDKLoginManagerLoginResult?, error : Error?) -> Void in
        if error != nil {
            // Process error
        }
        else if (result?.isCancelled)! {
            // Handle cancellations
        }
        else if (result?.grantedPermissions.contains("email"))! {
            print("result is: \(result)");
            self.fetchUserInfo()
            loginManager.logOut()
        }
    })
}


func fetchUserInfo() {
    if let accessToken = FBSDKAccessToken.current()?.tokenString {
        print("Token is available : \(accessToken)")

        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"]).start(completionHandler: { (connection : FBSDKGraphRequestConnection?, result : Any?, error : Error?) in

            if let error = error {
                print("Error \(error)")
            }
            else if let result  = result {
                print("result:\(result)")
            }
        })
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如果安装本机应用程序,则使用Facebook最新的SDK登录,然后在Android中未打开对话框

Chocolatey无法安装应用程序,“您如何打开此文件?” 而是打开对话框

无法在Visual Studio 2015(ASP.NET 5 Web应用程序)中打开发布对话框

如何从终端打开“运行应用程序”对话框?

通过外部应用程序打开松弛对话框

Windows 8应用程序的“打开文件”对话框

打开文件对话框时应用程序冻结

为什么我的iOS应用程序未显示在其他应用程序的“打开方式”对话框中?

如何确认对话框以在 TestCafe 中打开另一个应用程序

注册应用以从Safari的“共享”或“在...中打开”对话框打开无法正常工作。(尽管可以从其他应用程序使用)

如何在不打开Safari或任何其他浏览器的情况下在我的应用程序中起诉Facebook SDK登录对话框?

基于 MFC 对话框的应用程序无法两次调用对话框

通过macOS本机应用程序中的SwiftUI WKWebView调用时,如何使文件打开对话框起作用?

无法在应用程序中更改对话框的颜色

Android应用程序中的EULA对话框

即使已在设备中安装,Facebook本机登录也无法打开Facebook应用程序?

使用 OAuth2 和 Google 和 Safari 的 iOS 应用程序显示打开页面对话框

在关闭对话框后再次打开对话框时,应用程序崩溃并给出“ java.lang.IllegalStateException”

打开对话框不会打开相机应用程序

如何在Linux上的Java应用程序的“打开文件”对话框中显示隐藏文件(。*)?

在“选择应用程序”对话框列表中显示应用程序

ajax 调用在 Web 应用程序项目中引发意外的登录对话框

没有本地应用程序或对话框的Android Facebook登录

在模式对话框打开时如何处理锁定应用程序?

Win32 API:打开对话框窗口后,应用程序冻结

通过Web应用程序打开移动设备共享对话框

为什么再次打开应用程序时权限对话框消失?

如何在无需打开应用程序的情况下显示对话框

Setup.exe 不工作或打开 ClickOnce 应用程序的安装对话框很慢