简体   繁体   English

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

[英]FBSDKLoginManager not open login Dialog in native ios apps

I am new to iPhone development ,i want to do a facebook login from my native iOS simple application using latest facebook sdk 4. something ,i just want to open a facebook login dialog from Custom UIButton click,in my apps and for that i do below code in my button click method..我是 iPhone 开发的新手,我想使用最新的 facebook sdk 4 从我的原生 iOS 简单应用程序进行 facebook 登录。有些东西,我只想在我的应用程序中从自定义UIButton单击打开一个 facebook 登录对话框,为此我这样做下面是我的按钮单击方法中的代码..

- (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
            }
        }
    }];


}

This code is work something different,but i want to open a login dialog form Custom UIButton Click in the native iOS apps.此代码的工作方式有所不同,但我想在本机 iOS 应用程序中打开一个登录对话框表单 Custom UIButton Click。

So,please suggest the right way with some code,thanks in advance所以,请用一些代码建议正确的方法,提前致谢

Facebook login 4.x with custom button in Objective-C使用 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);
             }
         }];
    }
}

Facebook login 4.x with custom button in Swift使用 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)")
            }
        })
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS的Firebase Facebook登录(Swift)-使用未解析的标识符'FBSDKLoginManager' - Firebase facebook login for ios (swift) - Use of unresolved indentifier 'FBSDKLoginManager' iOS FBSDKLoginManager收到电子邮件 - iOS FBSDKLoginManager get email iOS:使用Facebook登录并打开Native Facebook应用程序 - iOS : Login with Facebook and open Native Facebook app 为什么我的iOS应用程序没有出现在其他应用程序的“打开方式”对话框中? - Why is my iOS app not showing up in other apps' “Open in” dialog? iOS / Swift / FBSDKLoginKit:使用FBSDKLoginManager()登录。logInWithReadPermissions通过获取result.isCancelled为true而失败。 - iOS/Swift/FBSDKLoginKit: Login using FBSDKLoginManager().logInWithReadPermissions gets failed by getting result.isCancelled to true 使用FBSDKLoginManager for IOS的​​安全问题 - Security concerns for using FBSDKLoginManager for IOS 仅使用弹出对话框登录本机(iOS或Android)Facebook? - Native (iOS or Android) Facebook login using popup dialog only? 如何防止iOS中的本机Facebook登录对话框? - how can I prevent native facebook login dialog in ios? 如何获取链接以在iOS Meteor应用程序的本机浏览器中打开? - How to get links to open in the native browser in iOS Meteor apps? 有什么办法可以从网页打开android / ios本机共享对话框 - Is there any way to open the android/ios native share dialog from a webpage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM