【问题标题】:I can't connect with Xcode Swift app to Firebase我无法将 Xcode Swift 应用程序连接到 Firebase
【发布时间】:2017-11-13 09:50:46
【问题描述】:

我遵循了各种教程并尝试了不同的方法,但没有任何帮助。我确定我做的一切都是正确的。但是当我尝试使用电子邮件登录时,Firebase 中没有任何事情发生(任何新用户或数据)。另外,我没有收到任何错误消息。

我认为我无法正确连接 ti firebase。 Cocoapods 或 Xcode 或 Firebase 上可能存在版本不匹配,但我无法弄清楚。

  • cocoapods-1.2.1
  • Xcode 8.3.3
  • 斯威夫特 3

AppDelegate:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


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

视图控制器:

import UIKit
import FirebaseAuth

class ViewController: UIViewController {
    @IBOutlet var emailTextField: UITextField!
    @IBOutlet var passTextField: UITextField!

    @IBAction func signUp(_ sender: Any) {

        let email = emailTextField.text!
        let password = passTextField.text!

        Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
            if error != nil{
                print(String(describing: error?.localizedDescription))
            }else{
                self.performSegue(withIdentifier: "goToHome", sender: self)
            }

        }
    }

控制台输出:

2017-06-12 05:17:22.628 emailAuth[11936] <Warning> [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at url.com
2017-06-12 05:17:22.636 emailAuth[11936] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.4001000 started
2017-06-12 05:17:22.636 emailAuth[11936] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see url.com)
2017-06-12 05:17:22.637 emailAuth[11936] <Notice> [Firebase/Analytics][I-ACS003007] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2017-06-12 05:17:22.678 emailAuth[11936] <Warning> [Firebase/Analytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled.
2017-06-12 05:17:22.695 emailAuth[11936] <Notice> [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled
2017-06-12 05:17:23.992594+0300 emailAuth[11936:2101062] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/mmuazekici/Library/Developer/CoreSimulator/Devices/4F8B6824-4D8D-4FB4-9E06-BFB49F220240/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-06-12 05:17:23.992826+0300 emailAuth[11936:2101062] [MC] Reading from private effective user settings.

【问题讨论】:

  • 你需要添加代码,所以我们知道你做了什么。

标签: ios swift xcode firebase firebase-realtime-database


【解决方案1】:

按照以下步骤操作

Podfile :-

pod 'Firebase/Core'
pod 'Firebase/Storage'
pod 'Firebase/Database'
pod 'Firebase/Auth'

在项目中拖放 Google-plist

GoogleService-Info.plist

在 AppDelegate 中添加以下代码

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FIRApp.configure()
}

第一步

import Firebase
import FirebaseAuth

步骤-2 登录操作

 guard let email = txtFldUserID.text?.lowercased(), let password = txtFldPassword.text else { return }
        FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user: FIRUser?, error) in

            if let error = error as NSError?{

                let errorName = (error.userInfo as NSDictionary).value(forKey: "error_name") as! String
                proxy.shared.displayFirbaseError(errName: errorName)
                return
            }else{
                 proxy.shared.displayStatusCodeAlert("You are login successfully")
  }

【讨论】:

  • 我想我正在使用新版本的 Firebase,因为当我尝试“FIRApp.configure()”时,Xcode 说“FIRApp 已重命名为 FirebaseApp”。有一些小的差异,但我正在关注文档,我的应该是正确的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-21
  • 2021-12-26
  • 2016-03-09
  • 2018-03-14
  • 1970-01-01
  • 2020-04-10
相关资源
最近更新 更多