Facebook与Parse无法登录Swift 2.0

时间:2015-09-15 11:13:33

标签: ios facebook swift parse-platform facebook-login

我的应用程序使用ParseSDK创建用户,我想在我的应用程序中实现简单的Facebook登录按钮,但我不能。我曾经多次尝试使用FacebookSDK和ParseSDK指南。但我失败了。你看看我的代码,请告诉我什么错了?

import UIKit
import CoreLocation
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseFacebookUtilsV4

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let locationManager = CLLocationManager()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Initialize Parse.
    Parse.enableLocalDatastore()
    Parse.setApplicationId(Constants.ParseAPIKey, clientKey: Constants.ParseClientKey)
    PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

    return true
}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    FBSDKAppEvents.activateApp()
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

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

有SDK文件。 enter image description here

有info.plist。 enter image description here

有我的LoginButton TableView Controller.swift文件。

    import UIKit
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseFacebookUtilsV4

class UserProfileTableViewController: UITableViewController {
@IBOutlet weak var statusLabel: UILabel!
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!

var user: User? {
    if let currentUser = PFUser.currentUser() {
        return User(user: currentUser)
    }
    return nil
}

override func viewWillAppear(animated: Bool) {
    self.configureStatusLabel()
}

func configureStatusLabel() {
    if user != nil { // User Logged In !
        if let name = user?.name,
            let surname = user?.surname {
                statusLabel.text = "Welcome, \(name) \(surname)"
        }
    } else {
        self.statusLabel.text = "You are not logged in"
    }
}

func face() {
    let permissions = ["public_profile", "email", "user_friends"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) { (user: PFUser?, error: NSError?) -> Void in
        if error == nil {
            print(user)
        } else {
            print("fail")
        }
    }

}

@IBAction func loginWithFacebook() {
    face()
}

@IBAction func logoutButton() {
    PFUser.logOut()
    self.configureStatusLabel()
}
}

当我点击我使用Facebook按钮登录时。 Safari打开并连接到这样的Facebook。 enter image description here

当我点击本页中的Tamam表示OK按钮时。它返回我的应用程序时出现此错误:

        2015-09-15 14:06:49.975 VetMapp[2233:81246] 
+[PFUser logInWithAuthTypeInBackground:authData:]:
 unrecognized selector sent to class 0x109fd8470
    2015-09-15 14:06:49.980 VetMapp[2233:81246] 
[Error]: Caught "NSInvalidArgumentException" 
with reason "+[PFUser logInWithAuthTypeInBackground:authData:]: 
unrecognized selector sent to class 0x109fd8470":
    (

首先感谢您阅读本文,我非常感谢您帮助解决此问题。谢谢!

1 个答案:

答案 0 :(得分:0)

对于Swift 2.0,你必须"白名单" FB服务器。您必须对Info.plist文件进行一些更改,所有这些都将重新运行。如果您使用的是pod,请确保也更新它们。 点击此链接,查看您需要在plist文件中添加的内容: https://developers.facebook.com/docs/ios/ios9