iOS Firebase 登录
Posted
技术标签:
【中文标题】iOS Firebase 登录【英文标题】:iOS firebase login 【发布时间】:2018-10-12 15:36:09 【问题描述】:我的 firebase 登录屏幕在尝试登录时崩溃
这是错误:
2018-05-02 09:39:25.937258-0400 noteCollab[2418:625945] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“提供的链接对电子邮件/链接符号无效-在。在尝试将其用于电子邮件/链接登录之前,请通过调用 isSignInWithEmailLink:link: on Auth 检查链接。 * 首先抛出调用栈: (0x1837d6d8c 0x1829905ec 0x1837d6c6c 0x1008aa3e0 0x10089c0b8 0x10089cd08 0x10089b808 0x101a29260 0x101a29220 0x101a37e80 0x101a2c730 0x101a38dd8 0x101a3febc 0x1833fbe70 0x1833fbb08) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)
这是我的代码:
//
// signinViewController.swift
// noteCollab
//
// Created by James Hall on 5/2/18.
// Copyright © 2018 James Hall. All rights reserved.
//
import UIKit
import Firebase
import FirebaseAuth
class signinViewController: UIViewController
@IBOutlet weak var signInSelector: UISegmentedControl!
@IBOutlet weak var signInLabel: UILabel!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var signInButton: UIButton!
var isSignIn:Bool = true
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view.
override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@IBAction func signInSelectorChanged(_ sender: UISegmentedControl)
isSignIn = !isSignIn
if isSignIn
signInLabel.text = "Sign In"
signInButton.setTitle("Sign In", for: .normal)
else
signInLabel.text = "Register"
signInButton.setTitle("Register", for: .normal)
@IBAction func signInButtonTapped(_ sender: UIButton)
if let email = emailTextField.text, let pass = passwordTextField.text
//check if its sign in or register
if isSignIn
//sign in the user with Firebase
Auth.auth().signIn(withEmail: email, link: pass) (user, error) in
// check that user isnt nil
if error != nil
print("cant sign in user")
else
self.performSegue(withIdentifier: "goToHome", sender: self)
else
//register the user with Firebase
Auth.auth().createUser(withEmail: email, password: pass) (user, error) in
// check that user isnt nil
if let u = user
//user is found, go to home
self.performSegue(withIdentifier: "goToHome", sender: self)
else
//error: check error and show message
【问题讨论】:
您是否在 firebase 控制台的身份验证方法中启用了电子邮件登录? 是的,我使用的登录名和密码与注册时使用的登录名和密码相同 你为什么用signIn(withEmail, link)而不是密码? 我试图只使用电子邮件和密码感谢 Adeel 你真的帮助了我 乐于助人???? 【参考方案1】:您的登录代码正在寻找电子邮件链接而不是密码。只需将“链接:”一词更改为“密码:”,您就应该一切就绪。
Auth.auth().signIn(withEmail: email, password: 密码)
【讨论】:
很高兴我能帮上忙!以上是关于iOS Firebase 登录的主要内容,如果未能解决你的问题,请参考以下文章
使用 Firebase 登录 iOS 13.2 的导航/Segue