Facebook登录在Swift中崩溃

时间:2015-10-31 20:06:08

标签: ios swift facebook-login

点击登录按钮,我遇到了崩溃问题。首先,我想详细说明我的申请。一切都与Facebook的教程相同。

Files Image

ViewController.swift

import UIKit
import Parse
import FBSDKCoreKit
import FBSDKLoginKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let testObject = PFObject(className: "TestObject")
    testObject["foo"] = "bar"
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        print("Object has been saved.")
    }
    let loginButton: FBSDKLoginButton = FBSDKLoginButton()
    loginButton.center = self.view.center
    self.view.addSubview(loginButton)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

AppDelegate.swift

import UIKit
import Parse
import Bolts
import FBSDKCoreKit
import FBSDKLoginKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    Parse.enableLocalDatastore()
    Parse.setApplicationId("----", clientKey: "----")
    PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
    return true
}


func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
//...//
}

我认为这个问题与return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)案有关。但是,我无法理解它为什么会崩溃。错误如下:

Error Total Error

1 个答案:

答案 0 :(得分:2)

在iOS 9.0中,您必须将其添加到plist文件中:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

我建议阅读有关App Transport Security的部分 - https://developer.apple.com/library/prerelease/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html

修改

此外,我发现这个答案有很多有用的资源:NSURLSession/NSURLConnection HTTP load failed on iOS 9