gpt4 book ai didi

ios - Beta 测试、Facebook 登录、Parse。某些用户的 Facebook 信息未保存到 Parse。 swift

转载 作者:行者123 更新时间:2023-11-30 13:51:54 25 4
gpt4 key购买 nike

parse result我正在进行 Beta 测试,到目前为止,已有 5 位用户完全成功登录和使用该应用程序。但是,3 个用户的 Facebook 信息未保存到 Parse,并且当他们尝试转移到加载用户个人资料的 VC 时,应用程序崩溃。我不明白发生了什么事。这是我的登录代码,它会显得非常业余和困惑,所以预先道歉! (新手但正在尝试)应用程序委托(delegate):

import UIKit
import Bolts
import Parse
import ParseUI
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// code in here to check devices just left it out as it was too much information to paste.
}

// parse info and connection

Parse.enableLocalDatastore()

Parse.setApplicationId("",
clientKey: "")


PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

PFUser.enableAutomaticUser()

let defaultACL = PFACL();

defaultACL.setPublicReadAccess(true)

PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)


if application.applicationState != UIApplicationState.Background {

let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var noPushPayload = false;
if let options = launchOptions {
noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
}
if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}
if application.respondsToSelector("registerUserNotificationSettings:") {
let userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types: UIRemoteNotificationType = [UIRemoteNotificationType.Badge, UIRemoteNotificationType.Alert, UIRemoteNotificationType.Sound]
application.registerForRemoteNotificationTypes(types)
}


return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()

PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.", error)
}
}
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
print("Push notifications are not supported in the iOS Simulator.")
} else {
print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Inactive {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}

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

func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
}

查看 Controller :

import UIKit
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseUI

class LoginViewController: UIViewController {

var firstName: String!
var lastName: String!

@IBAction func logInWithFacebook(sender: AnyObject) {

let permissions = ["public_profile", "email"]


PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: {

(user: PFUser?, error: NSError?) -> Void in

if let error = error {

print(error)

} else {
// user successfully signed in:


if let user = user {
self.performSegueWithIdentifier("registerFacebookSegue", sender: self)

}

}
})


}

override func viewDidAppear(animated: Bool) {

//to log user out

// PFUser.logOut()

// segue if user is logged in:


if let username = PFUser.currentUser()?.username {


self.performSegueWithIdentifier("loggedInProfileSegue", sender: self)

}


}

override func viewDidLoad() {
super.viewDidLoad()



if(FBSDKAccessToken.currentAccessToken() != nil) {

print("user logged in")
} else {
print("user not logged in")
}
}


override func prefersStatusBarHidden() -> Bool {
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

从无法正常工作的用户那里获取 Facebook 密码,并尝试使用 xcode 登录并且连接的手机出现此错误:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.' * First throw call stack: (0x183608f48 0x1980cbf80 0x183608e90 0x1000e49a8 0x1000e8e98 0x10012d344 0x1000e8eec 0x100062ec8 0x1000976f4 0x10009e1c0 0x10009df90 0x10009da44 0x1834ff990 0x1834ff800 0x10009d800 0x10009cd00 0x10009aed4 0x100097eb8 0x100097e10 0x100098288 0x182e9b6a8 0x182e9b638 0x182e9b7ac 0x182d074fc 0x182df5b38 0x101461c68 0x10146b40c 0x182cf3ce4 0x1834ec6cc 0x182cf3bc8 0x182cf3a88 0x182cf38b4 0x1835c0544 0x1835bffd8 0x1835bdcd8 0x1834ecca0 0x18e728088 0x188c04ffc 0x10006e488 0x19891a8b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

最佳答案

问题是我在请求中要求提供电子邮件,但并非所有 Facebook 帐户都有。 a. 有效的电子邮件地址和 b.任何链接的电子邮件地址。所以我不得不删除这个请求并要求用户单独输入他们的电子邮件地址。

关于ios - Beta 测试、Facebook 登录、Parse。某些用户的 Facebook 信息未保存到 Parse。 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34159133/

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