Parse/FaceBookSDK 崩溃 Swift

Parse/FaceBookSDK crash with Swift

我非常需要帮助。

我在这里用 swift 编程有一段时间了,但我似乎找不到以前遇到过这个问题的人。

让我描述一下问题: 每当我尝试 运行 我的应用程序时,它都会在 AppDelegate 中崩溃,就在第一行 "SIGABRT"。委员会说“'The class PFUser must be registered with registerSubclass before using Parse.'”,这让我完全不知所措,因为我没有将任何远程接触 PFUser 的东西分类。

我认为这与我一直试图集成的 FacebookSDK(4.something,截至 7 月 2 日的最新版本)有关,但即使我将其从项目中删除,事情仍然存在问题。也可能与我刚刚将 Parse 更新到 1.7.5 的方式有关,但我真的不知道了。

这是我试过的方法

  1. 清理、重建、重启等
  2. 在 App Delegate 中使用 "Import Parse" 导入解析,而不是使用 header 桥。
  3. 重新安装所有框架,多次。
  4. 更改 didFinishLaunchingWithOptions 中的顺序

这是我的代码:

import UIKit
import iAd
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {



var window: UIWindow?
var UIiAd: ADBannerView = ADBannerView()


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

    Parse.setApplicationId("2NFm7aqXQIdO0JCaxH8bwveJhRhV5iEGQWDVpDgO", clientKey: "jIhPRyAXdUVnKuFh7ka7OAQjp2pcVi0LB2WWNXcg")

    PFAnalytics.trackAppOpenedWithLaunchOptionsInBackground(launchOptions, block: nil)

    GMSServices.provideAPIKey("AIzaSyAM5ff80Oc-1n9UJV1wZjX6ElFP-6PD2eI")

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



    FBSDKLoginManager.renewSystemCredentials { (result:ACAccountCredentialRenewResult, error:NSError!) -> Void in }




    PFPurchase.addObserverForProduct("kinkstrtext.addevent") {
        (transaction: SKPaymentTransaction?) -> Void in
        println("purchased");
    }

    let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound

    if application.respondsToSelector("isRegisteredForRemoteNotifications")
    {
        // iOS 8 Notifications

        let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories:nil)


        UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
    }
    else
    {
        // iOS < 8 Notifications
        application.registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)

    }


    var navigationBarAppearace = UINavigationBar.appearance()

    var btnColor:UIColor
    btnColor = UIColor(red: 0.99, green: 0.99, blue: 1, alpha: 1)
    var barColor:UIColor
    barColor = UIColor(red: 0.706, green: 0.506, blue: 0.678, alpha: 1.0)
    var titleColor:UIColor
    titleColor = UIColor(red: 0.99, green: 0.99, blue: 1, alpha: 1)

    UIApplication.sharedApplication().statusBarStyle = .LightContent


    navigationBarAppearace.tintColor = btnColor  // Back buttons and such
    navigationBarAppearace.barTintColor = barColor  // Bar's background color

    navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:titleColor]  // Title's text color

    return true
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {

    UIApplication.sharedApplication().registerForRemoteNotifications()

}

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

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

}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {

    println(error.localizedDescription)

}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    NSNotificationCenter.defaultCenter().postNotificationName("getMessage", object: nil)

}

func applicationWillResignActive(application: UIApplication) {
}

func applicationDidEnterBackground(application: UIApplication) {
}

func applicationWillEnterForeground(application: UIApplication) {
}

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

func applicationWillTerminate(application: UIApplication) {        
}

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

}

这是我的 header:

#import <Parse/Parse.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <Bolts/Bolts.h>

#import <GoogleMaps/GoogleMaps.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

任何帮助都会很棒!

谢谢,

-麦克莱恩

使用最新的 SDK,根据我的经验,您实际上不需要桥接 headers,将 SDK 添加到那里实际上会导致问题!因此,请尝试从 header 中删除它们,并在 class 中使用您正在使用它们的导入。

import Parse
import FBSDKCoreKit
import FBSDKLoginKit

事实证明,解析 1.6 和 1.7 之间存在问题,一直导致此崩溃。我错误地声明了一个 PFUser 变量,并且不知道。解析 1.7 关心,而 1.6 没有。我不知道会有什么不同,并认为它与 facebook SDK 有关(我多么专业)。

罪魁祸首的代码是 var currentUser:PFUser = PFUser(),我可以自由编辑它。我希望这可以帮助其他人了解 Parse!