簡體   English   中英

PARSE-STARTER SWIFT:“ NSInternalInconsistencyException”,原因:“在使用Parse之前,必須向registerSubclass注冊PFUser類

[英]PARSE - STARTER SWIFT : 'NSInternalInconsistencyException', reason: 'The class PFUser must be registered with registerSubclass before using Parse

我正在為我的應用程序制作一個簡單的登錄屏幕。 最初,當我將PFObject和PFUser設置為在后台保存時,它正在運行,突然間,我又添加了幾行代碼,然后繁榮,它停止工作並出現以下錯誤:

2015-10-24 04:49:09.101 ParseStarterProject-Swift [936:44671] *由於未捕獲的異常“ NSInternalInconsistencyException”而終止應用程序,原因:“在使用Parse之前,必須向registerSubclass注冊PFUser類。” *首先拋出調用堆棧:

我的代碼很簡單:

import UIKit
import Parse

class ViewController: UIViewController, UIApplicationDelegate {

    //registration screen VARIABLES

    var user = PFUser()
    //Password
    @IBOutlet weak var password: UITextField!
    //UserName
    @IBOutlet weak var userName: UITextField!
    //Email
    @IBOutlet weak var userEmailAddress: UITextField!

    //registration Screen METHODS

    //Facbook
    @IBAction func facebookRegistration(sender: AnyObject) {
    }
    //Twitter
    @IBAction func twitterRegistration(sender: AnyObject) {
    }
    //Email
    @IBAction func emailRegistartion(sender: AnyObject)
    {
    //Check if any fields are nil
    if userEmailAddress.text == "" || userName.text == "" || password.text == ""
    {
        //provide and alert
        self.alert("oops", yourMessage: "looks like you are missing some fields", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "ok", alertStyle: UIAlertActionStyle.Default)
        self.activityIndicator(frame: 0, frame: 0, frame: 50, frame: 50, indicatorViewStyle: .White)
    }
        //implement email confirmation alert
    else{
        self.createUser(userName.text, password: password.text, email: userEmailAddress.text)

    }
}

//Sign In 

@IBAction func signInButton(sender: AnyObject) {
}


//THIS IS A GENERIC FUNCTION TO CREATE A PFUSER
func createUser (username: String!, password: String!, email: String!)
{
    let user = PFUser()
    user.username = username
    user.password = password
    user.email = email
    user.signUpInBackgroundWithBlock { (saved: Bool, error:NSError?) -> Void in
        if let error = error {
            _ = error.userInfo["error"] as? NSString
}
        else
        {
            self.alert("Registered!", yourMessage: "You have successfully registered, please check your email for verification.", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "Sweet", alertStyle: UIAlertActionStyle.Default)
        }
                            }

}

//THIS IS THE GENRIC ALERT FUNCTION

func alert (alertTitle: String?, yourMessage: String?, yourPrefferredStyle:UIAlertControllerStyle, actionTitle: String?, alertStyle: UIAlertActionStyle)
{
    let alert = UIAlertController(title: (alertTitle), message:(yourMessage), preferredStyle:(yourPrefferredStyle))
    alert.addAction((action: UIAlertAction(title: (actionTitle), style: (alertStyle), handler: { (action) -> Void in
        self.dismissViewControllerAnimated(true, completion: nil)})))
    self.presentViewController(alert, animated: true, completion: nil)
}

//THIS IS A GENEREIC LOADING INDICATION ANIMATION

func activityIndicator (frame x: CGFloat?, frame y: CGFloat?, frame Width: CGFloat?, frame height: CGFloat?, indicatorViewStyle: UIActivityIndicatorViewStyle)
{
  var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
    activityIndicator.center = self.view.center
    activityIndicator.hidesWhenStopped = true
    activityIndicator.activityIndicatorViewStyle = indicatorViewStyle
    view.addSubview(activityIndicator)
    activityIndicator.startAnimating()
    UIApplication.sharedApplication().beginIgnoringInteractionEvents()

}

如您所見,我已經創建了自己的函數來創建PFuser,這樣,只要用戶每次輸入新的憑據(即命中寄存器),我都可以調用該函數...但是它不起作用。 希望有人能幫忙!

您需要在應用程序委托中調用setup方法。

[Parse setApplicationId:@"xxx" clientKey:@"xxx"];

https://parse.com/apps/quickstart#parse_data/mobile/ios/native/new

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM