我的应用程序在与facebook SDK集成时崩溃了

时间:2015-09-15 10:14:11

标签: ios swift facebook-login

screenshot我的应用在点击facebook登录按钮时崩溃,显示FBSDKInternalUtility.m:484错误

这是我的代码enter image description here

import UIKit

class ViewController: UIViewController ,FBSDKLoginButtonDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if (FBSDKAccessToken.currentAccessToken() != nil)
    {
        // User is already logged in, do work such as go to next view controller.
    }
    else
    {
        let loginView : FBSDKLoginButton = FBSDKLoginButton()
        self.view.addSubview(loginView)
        loginView.center = self.view.center
        loginView.readPermissions = ["public_profile", "email", "user_friends"]
        loginView.delegate = self
    }
}

// Facebook Delegate Methods

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    print("User Logged In")

    if ((error) != nil)
    {
        // Process error
    }
    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.contains("email")
        {
            // Do work
        }
    }
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    print("User Logged Out")
}

func returnUserData()
{
    let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

        if ((error) != nil)
        {
            // Process error
            print("Error: \(error)")
        }
        else
        {
            print("fetched user: \(result)")
            let userName : NSString = result.valueForKey("name") as! NSString
            print("User Name is: \(userName)")
            let userEmail : NSString = result.valueForKey("email") as! NSString
            print("User Email is: \(userEmail)")
        }
    })
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

我有一个桥接标题并将其添加到Xcode的项目构建设置中,但它仍显示错误

感谢

3 个答案:

答案 0 :(得分:6)

我认为您可能遇到了iOS9兼容性问题:

有类似的问题,我通过使用以下内容更新info.plist来修复它:



<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
</array>
&#13;
&#13;
&#13;

这是描述更改的Facebook页面:

https://developers.facebook.com/docs/ios/ios9

答案 1 :(得分:0)

在我看来,你的loginButton函数在开始时缺少'{'。

另外我相信你的if语句'如果result.grantedPermissions.contains(“email”)'需要有其他条件。

您在loginButton函数中描述的状态可能也需要一些正文。目前描述了状态,但是当达到任何描述的状态时,没有代码可以执行。

答案 2 :(得分:0)

我遇到了同样的问题,我删除了这些库,并将它们从“链接的框架和库”项目中添加并重新链接,并且工作正常。

希望它有所帮助, 安多尼。

相关问题