gpt4 book ai didi

ios - 使用未解析的标识符 'FIRAuth'(Swift 2、Firebase 3.x)

转载 作者:IT王子 更新时间:2023-10-29 08:04:17 24 4
gpt4 key购买 nike

更新到新的 Firebase。创建了一个新的登录 VC,一切正常,没有错误。

尝试复制这个新教程:https://codelabs.developers.google.com/codelabs/firebase-ios-swift/index.html?index=..%2F..%2Findex#0

现在我突然在我的 VC 中收到错误 Use of unresolved identifier 'FIRAuth'。

我已经尝试重新安装 pods 文件但没有任何运气,似乎有时如果它添加“import Firebase”然后删除它应用程序将编译,似乎没有韵律或原因它有时有效,有时无效:

这是我的代码:

import UIKit
import FirebaseAuth


class SignInViewController: UIViewController {

@IBOutlet weak var emailField: UITextField!

@IBOutlet weak var passwordField: UITextField!

override func viewDidAppear(animated: Bool) {
if let user = FIRAuth.auth()?.currentUser { //error here
self.signedIn(user)
}
}

@IBAction func didTapSignIn(sender: AnyObject) {
// Sign In with credentials.
let email = emailField.text
let password = passwordField.text
FIRAuth.auth()?.signInWithEmail(email!, password: password!) { //error here (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.signedIn(user!)
}
}
@IBAction func didTapSignUp(sender: AnyObject) {
let email = emailField.text
let password = passwordField.text
FIRAuth.auth()?.createUserWithEmail(email!, password: password!) { // error here(user, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.setDisplayName(user!)
}
}

func setDisplayName(user: FIRUser) {
let changeRequest = user.profileChangeRequest()
changeRequest.displayName = user.email!.componentsSeparatedByString("@")[0]
changeRequest.commitChangesWithCompletion(){ (error) in
if let error = error {
print(error.localizedDescription)
return
}
self.signedIn(FIRAuth.auth()?.currentUser) //error here
}
}

@IBAction func didRequestPasswordReset(sender: AnyObject) {
let prompt = UIAlertController.init(title: nil, message: "Email:", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction.init(title: "OK", style: UIAlertActionStyle.Default) { (action) in
let userInput = prompt.textFields![0].text
if (userInput!.isEmpty) {
return
}
FIRAuth.auth()?.sendPasswordResetWithEmail(userInput!) { //error here (error) in
if let error = error {
print(error.localizedDescription)
return
}
}
}
prompt.addTextFieldWithConfigurationHandler(nil)
prompt.addAction(okAction)
presentViewController(prompt, animated: true, completion: nil);
}

func signedIn(user: FIRUser?) {
MeasurementHelper.sendLoginEvent()

AppState.sharedInstance.displayName = user?.displayName ?? user?.email
AppState.sharedInstance.photoUrl = user?.photoURL
AppState.sharedInstance.signedIn = true
NSNotificationCenter.defaultCenter().postNotificationName(Constants.NotificationKeys.SignedIn, object: nil, userInfo: nil)
// performSegueWithIdentifier(Constants.Segues.SignInToFp, sender: nil)
}

}

有人知道为什么会这样吗?

最佳答案

对于 future 的读者:

确保在您的 Podfile 中包含以下内容:

pod 'Firebase/Auth'

安装 pod 后,使用:

导入 FirebaseAuth

这就是为我解决的问题。

关于ios - 使用未解析的标识符 'FIRAuth'(Swift 2、Firebase 3.x),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37345465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com