繁体   English   中英

使用Parse的Facebook无法登录Swift 2.0

[英]Facebook with Parse can't Login Swift 2.0

我的应用程序使用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文件。 在此处输入图片说明

有info.plist。 在此处输入图片说明

有我的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。 在此处输入图片说明

当我点击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":
    (

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

对于Swift 2.0,您必须将FB服务器“白名单”。 您必须对Info.plist文件进行一些更改,所有这些都将再次起作用。 如果您使用的是Pod,请确保同时更新它们。 单击此链接以查看需要在plist文件中添加的内容: https : //developers.facebook.com/docs/ios/ios9

暂无
暂无

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

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