当我尝试使用Auth用户访问Firebase时,可以,但是当我尝试编写数据库用户的电子邮件地址时,会收到错误消息。
我的代码:
import UIKit
import Firebase
class ViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var sifreField: UITextField!
@IBOutlet weak var sifre1Field: UITextField!
var ref = Database.database().reference()
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 kayitBtn(_ sender: Any)
{
if(sifreField.text != sifre1Field.text)
{
print("****error****")
}
else if ( !(emailField.text?.isEmpty)! || !(sifreField.text?.isEmpty)! || !(sifre1Field.text?.isEmpty)! )
{
Auth.auth().createUser(withEmail: emailField.text!, password: sifreField.text!) { (user, error) in
if error != nil
{
print ("***error***")
}
else if ( !(self.emailField.text?.isEmpty)! || !(self.sifreField.text?.isEmpty)! || !(self.sifre1Field.text?.isEmpty)! )
{
self.ref.child("users").child((user?.uid)!).setValue(["email": self.emailField.text!])
print("database ok")
}
}
}
}
}
我的AppDelegate.swift(在import Firebase
中添加了didFinishLaunchingWithOptions
和FirebaseApp.configure()):
import UIKit
import CoreData
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
我的控制台错误:
我现在该怎么办?谢谢你的一切。
答案 0 :(得分:3)
var ref: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
}
这将解决您的问题,并且该应用不会崩溃。