gpt4 book ai didi

ios - Facebook 与 Parse 无法登录 Swift 2.0

转载 作者:行者123 更新时间:2023-11-30 14:04:31 25 4
gpt4 key购买 nike

我的应用程序使用 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 时,这意味着此页面中的“确定”按钮。它返回我的应用程序并出现以下错误:

        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

关于ios - Facebook 与 Parse 无法登录 Swift 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com