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

标签 ios swift xcode firebase firebase-authentication

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

我检查了我的日志以查看是否出现任何问题,但我什么也没看到。我刚开始使用 Xcode 和 Swift,所以我不知道我是否犯了一个愚蠢的错误,但这是我的代码。

我还安装了 Google plist 和 pod,所以我认为这不是问题。

注册 Controller .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:.
}


}

最佳答案

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

改变

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

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

关于ios - iOS 应用程序的注册页面没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40961926/

相关文章:

ios - Swift 5 iOS13 - 继续到另一个 Storyboard或未连接的 View Controller 而不创建卡 View

ios - "App' 在此上下文中对于类型查找不明确。”在 swiftui 项目中导入 Realm 时出现此错误

swift - Swift 中的@selector()?

objective-c - 将 Storyboard中的 UITableView 更改为 UIView

ios - 图标在 iPhone 主屏幕上看起来很奇怪

ios - Xcode 5 和本地化问题 - 如何使用原始语言?

android - Cordova:android 和 ios 平台可以有不同的应用程序 ID 吗?

ios - 由于 SFSafariViewController,YSLSearchViewController 无法在 iOS 9 上工作

ios - 使用 Swift 4 Decodable 将字符串 JSON 响应转换为 bool 值

swift - 当部分包含空行时删除 UITableHeader 标题