注册iOS应用程序没有响应的页面

时间:2016-12-04 18:15:02

标签: ios swift xcode firebase firebase-authentication

我尝试为我的应用程序制作一个注册部分,但是,当我点击注册时,它似乎什么都不做。我部分地使用了我的知识和教程来构建它,但是当我点击它时,没有任何反应。

我检查了我的日志,看看是否有任何问题,但我根本看不到任何东西。我是使用Xcode和Swift的新手,所以我不知道我是否犯了一个愚蠢的错误,但这是我的代码。

我也安装了Google plist和pods,所以我不认为这是一个问题。

SignUpController.swift

import Foundation
import UIKit
import Firebase
import FirebaseAuth
import FirebaseDatabase

class SignUpController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var Email: UITextField!

@IBOutlet weak var Password: UITextField!

@IBAction func Create(_ sender: AnyObject) {
    let Email = self.Email.text!
    let Password = self.Password.text!


    if Email != "" && Password != "" {
        FIRAuth.auth()?.signIn(withEmail: Email, password: Password, completion: { (user, error) in
            if error == nil{
                FIREmailPasswordAuthProvider.credential(withEmail: Email, password: Password)
                self.dismiss(animated: true, completion: nil)
            }
            print("Error")
        })
    }
    else{
        let alert = UIAlertController(title: "Error", message: "Enter email and password!", preferredStyle: .alert)
        let action = UIAlertAction(title: "test", style: .default, handler: nil)
        alert.addAction(action)
        self.present(alert, animated: true, completion: nil)
    }
    func Cancel(_ sender: AnyObject) {
        self.dismiss(animated: true, completion: nil)
    }
}
override func viewDidLoad() {
    super.viewDidLoad()
    Email.delegate = self
    Password.delegate = self
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    textField.resignFirstResponder()
    return true
}
}

AppDelegate.swift

import UIKit
import Firebase
import FirebaseDatabase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

override init() {
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
}


private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    return true
}

@objc(applicationWillResignActive:) func applicationWillResignActive(_ application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

1 个答案:

答案 0 :(得分:1)

您似乎正在尝试登录用户,而不是注册用户。

更改

FIRAuth.auth()?.signIn(withEmail: Email, password: Password, completion: { (user, error) in

FIRAuth.auth()?.createUser(withEmail: Email, password: Password, completion: { (user, error) in