繁体   English   中英

使用Firebase进行寄存器功能时Swift 3中的错误

[英]Error in Swift 3 when making a register function with Firebase

我正在使用Firebase在Xcode中使用聊天应用程序,每次我输入详细信息并单击“注册”时,都会出现以下错误:

2017-03-08 22:05:45.757934 wapp[804:226081] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-03-08 22:05:45.766072 wapp[804:226081] [MC] Reading from public effective user settings.
2017-03-08 22:05:49.211930 wapp[804:226158] 0x1701576b0 Copy matching assets reply: XPC_TYPE_DICTIONARY  <dictionary: 0x1701576b0> { count = 1, transaction: 0, voucher = 0x0, contents =
    "Result" => <int64: 0x170222460>: 29
}
2017-03-08 22:05:49.218786 wapp[804:226158] 0x170158260 Daemon configuration query reply: XPC_TYPE_DICTIONARY  <dictionary: 0x170158260> { count = 2, transaction: 0, voucher = 0x0, contents =
    "Dictionary" => <dictionary: 0x1701581b0> { count = 1, transaction: 0, voucher = 0x0, contents =
        "ServerURL" => <dictionary: 0x170158100> { count = 3, transaction: 0, voucher = 0x0, contents =
            "com.apple.CFURL.magic" => <uuid: 0x170243c00> C3853DCC-9776-4114-B6C1-FD9F51944A6D
            "com.apple.CFURL.string" => <string: 0x170249ab0> { length = 30, contents = "https://mesu.apple.com/assets/" }
            "com.apple.CFURL.base" => <null: 0x1aca0fe80>: null-object
        }
    }
    "Result" => <int64: 0x170222b40>: 0
}
2017-03-08 22:05:49.222048 wapp[804:226158] [MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker
2017-03-08 22:05:51.059259 wapp[804:226144] 0x170157e40 Copy matching assets reply: XPC_TYPE_DICTIONARY  <dictionary: 0x170157e40> { count = 2, transaction: 0, voucher = 0x0, contents =
    "Assets" => <data: 0x170663080>: { length = 4531 bytes, contents = 0x62706c6973743030d400010002000300040005000601a801... }
    "Result" => <int64: 0x170223440>: 0
}
2017-03-08 22:05:51.076469 wapp[804:226144] 0x170157d90 Copy assets attributes reply: XPC_TYPE_DICTIONARY  <dictionary: 0x170157d90> { count = 2, transaction: 0, voucher = 0x0, contents =
    "Attributes" => <data: 0x170664180>: { length = 302 bytes, contents = 0x62706c6973743030d40102030405061a1b58247665727369... }
    "Result" => <int64: 0x170225820>: 0
}
2017-03-08 22:05:51.083455 wapp[804:226144] 0x174157760 Copy assets attributes reply: XPC_TYPE_DICTIONARY  <dictionary: 0x174157760> { count = 3, transaction: 0, voucher = 0x0, contents =
    "Attributes" => <data: 0x174a6dcc0>: { length = 515 bytes, contents = 0x62706c6973743030d4010203040506232458247665727369... }
    "Result" => <int64: 0x174228c60>: 0
    "SandboxExtension" => <string: 0x17425ad30> { length = 258, contents = "f830455e55a12e4770dcf1a97c2776f1ec0d21e8;00000000;00000000;0000000000000015;com.apple.assets.read;00000001;01000003;000000000001d4e5;/private/var/MobileAsset/Assets/com_apple_MobileAsset_LinguisticData/12124144ce3f42648e61a6a8064d2fb9b2d42605.asset/AssetData" }
}
2017-03-08 22:05:51.091697 wapp[804:226144] 0x170158260 Copy assets attributes reply: XPC_TYPE_DICTIONARY  <dictionary: 0x170158260> { count = 2, transaction: 0, voucher = 0x0, contents =
    "Attributes" => <data: 0x170660ac0>: { length = 302 bytes, contents = 0x62706c6973743030d40102030405061a1b58247665727369... }
    "Result" => <int64: 0x170225460>: 0
}
2017-03-08 22:05:51.097962 wapp[804:226144] 0x170156160 Copy assets attributes reply: XPC_TYPE_DICTIONARY  <dictionary: 0x170156160> { count = 3, transaction: 0, voucher = 0x0, contents =
    "Attributes" => <data: 0x170664380>: { length = 515 bytes, contents = 0x62706c6973743030d4010203040506232458247665727369... }
    "Result" => <int64: 0x170227140>: 0
    "SandboxExtension" => <string: 0x170246cf0> { length = 258, contents = "b14c014aebf7c920f6a59b1d027c4314a3c0578a;00000000;00000000;0000000000000015;com.apple.assets.read;00000001;01000003;000000000001d4f2;/private/var/MobileAsset/Assets/com_apple_MobileAsset_LinguisticData/2e428a59a8c74acf82b249f73fcbbc785b892f69.asset/AssetData" }
}
2017-03-08 22:05:58.289944 wapp[804:226081] *** Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(setValue:withCompletionBlock:) Cannot store object of type UITextField at username. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'
*** First throw call stack:
(0x18dc521c0 0x18c68c55c 0x1000e2a68 0x1000e1f70 0x1000e24a8 0x1000e1f70 0x1000e1ea4 0x100111130 0x100110f68 0x10003b784 0x10003a11c 0x10003a218 0x10003a344 0x100d2d25c 0x100d2d21c 0x100d32284 0x18dbfff2c 0x18dbfdb18 0x18db2c048 0x18f5b2198 0x193b182fc 0x193b13034 0x10003d420 0x18cb105b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我的ViewController.swift文件如下:

//
//  ViewController.swift
//  wapp
//
//  Created by Julius on 3/8/17.
//  Copyright © 2017 Julius. All rights reserved.
//

import UIKit
import Firebase
import FirebaseAuth
import FirebaseDatabase
import FirebaseCore

class ViewController: UIViewController {

    @IBOutlet weak var usernameTxtField: UITextField!
    @IBOutlet weak var emailTxtField: UITextField!
    @IBOutlet weak var passwordTxtField: UITextField!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func loginBtnPressed(_ sender: Any) {
        login()

    }

    @IBAction func registerBtnPressed(_ sender: Any) {
        register()


    }

    func login() {
        if usernameTxtField.text != "" && emailTxtField.text != "" && passwordTxtField.text != "" {
            FIRAuth.auth()?.signIn(withEmail: emailTxtField.text!, password: passwordTxtField.text!, completion: {

                user, error in

                if error != nil {
                    print(error?.localizedDescription)
                } else {
                    Helper.helper.switchToNavigationVC()
                }

            })
        } else {
            // Do something later
        }
    }

    func register() {
        if usernameTxtField.text != "" && emailTxtField.text != "" && passwordTxtField.text != "" {
            FIRAuth.auth()?.createUser(withEmail: emailTxtField.text!, password: passwordTxtField.text!, completion:
                {

                user, error in

                if error != nil {
                    print(error?.localizedDescription)
                } else {
                    let uid = FIRAuth.auth()?.currentUser?.uid
                    let databaseRef = FIRDatabase.database().reference()
                    let userData : [String : Any] = ["email" : self.emailTxtField!,
                                                     "uid" : uid!,
                                                     "username" : self.usernameTxtField!]
                    databaseRef.child("Users").child(uid!).setValue(userData){ (error, ref) -> Void in
                    Helper.helper.switchToNavigationVC()
                }
                    }

            })
    }


}
}

任何帮助,将不胜感激 ;)

这是问题所在:

代替:

   let userData : [String : Any] = ["email" : self.emailTxtField!,
                                                         "uid" : uid!,
                                                         "username" : self.usernameTxtField!]

采用:

   let userData : [String : Any] = ["email" : self.emailTxtField!.text,
                                                         "uid" : uid!,
                                                         "username" : self.usernameTxtField!.text]

“ self.emailTxtField!.text”和“ self.usernameTxtField!.text”有所不同。 您正在尝试设置UITextField错误已显示:

2017-03-08 22:05:58.289944 wapp[804:226081] *** Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(setValue:withCompletionBlock:) Cannot store object of type UITextField at username. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'
*** First throw call stack:

暂无
暂无

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

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