简体   繁体   中英

Sign up page for iOS app not responding

I tried to make a sign up section for my application, however, when I click sign up, it seems to do nothing. I partly used my knowledge and a tutorial to build it, but when I click it, nothing happens.

I checked my logs to see if anything came up, but I don't see anything at all. I'm new to using Xcode and Swift, so I don't know if I made a stupid mistake or not, but here is my code.

I also have my Google plist and pods installed, so I don't think that's a problem.

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:.
}


}

It seems like you are trying to sign in the user, instead of signing up the user.

Change

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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