简体   繁体   English

iPhone中的Facebook SDK错误

[英]Facebook sdk error in iPhone

I have used the facebook new sdk for getting the information of user. 我已经使用了facebook new sdk来获取用户信息。 But when i run on device it gives me the error like "The Operation couldn't be completed. (com.facebook.sdk error 2.)." 但是,当我在设备上运行时,它给我类似“操作无法完成。(com.facebook.sdk错误2)”的错误。 And also i have signed in facebook from device setting. 而且我已经从设备设置中登录了Facebook。

This worked for me: 这为我工作:

Go to the settings app of your iPhone. 转到iPhone的设置应用。
Open your Facebook Settings 打开你的Facebook设置

Scroll down to your app and make sure your app allows facebook interaction. 向下滚动到您的应用,并确保您的应用允许Facebook互动。


This could happen on any device, therefore in your app you will have to make sure to handle this error correctly. 任何设备上都可能发生这种情况,因此在您的应用中,您必须确保正确处理此错误。 I reckon you give the user feedback why Login With Facebook failed and ask the user to check their Facebook settings on their device. 我想您可以向用户提供反馈,说明“使用Facebook登录失败”的原因,并要求用户在设备上检查其Facebook设置。

- (void)facebookSessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            // handle successful login here
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];

            if (error) {
                // handle error here, for example by showing an alert to the user
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"
                                                                message:@"Facebook login failed. Please check your Facebook settings on your phone."
                                                               delegate:nil
                                                      cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
                [alert show];
            }
            break;
        default:
            break;
    }

首先检查您的捆绑包标识符,并确保它与您在注册​​应用程序时在https://developers.facebook.com/上输入的标识符相同。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM