- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试安装 "drop-in" authentication solution来自 Firebase自动发送您的应用程序用户通过 Google、Facebook 或电子邮件/密码屏幕以对他们进行身份验证。
我的问题是 Firebase 提供的代码似乎是使用 Objective C 而不是 Swift 的旧 iOS 语言,而且一些 Swift 指导代码行似乎已经过时,而且我找不到新的行'应该使用。
我主要根据 Github 插入式解决方案这一部分的说明来构建我的代码:FirebaseUI Authentication .
这导致了以下代码,其中一些我不得不猜测,因为 Xcode 无法识别 .authUI()
in let authUI = FIRAuthUI.authUI( )
。该应用程序不会崩溃,但它也根本不会启动身份验证过程。这只是一个空白屏幕。
import UIKit
import Firebase
import FirebaseAuth
import FirebaseDatabaseUI
import FirebaseAuthUI
import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI
import FBSDKCoreKit
import FBSDKLoginKit
class LoginController: UIViewController, FIRAuthUIDelegate {
var db = FIRDatabaseReference.init()
var kFacebookAppID = "15839856152xxxxx"
var kGoogleClientID = "9042861xxxxx-6qq4gmeos07gpgmgt54ospv3fvpg0724.apps.googleusercontent.com"
override func viewDidLoad() {
super.viewDidLoad()
//FIRApp.configure()
let authUI = FIRAuthUI.defaultAuthUI()
let facebookAuthUI = FIRFacebookAuthUI(appID: kFacebookAppID)
let googleAuthUI = FIRGoogleAuthUI(clientID: kGoogleClientID)
//let emailAuthUI = FIREmailPasswordAuthProvider
authUI?.providers = [facebookAuthUI, googleAuthUI]
// Present the auth view controller and then implement the sign in callback.
let authViewController = authUI
authUI?.authViewController()
}
func authUI(authUI: FIRAuthUI, didSignInWithUser user: FIRUser?, error: NSError?) {
if error != nil {
//Problem signing in
}else {
//User is in!
}
}
func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String
return FIRAuthUI.defaultAuthUI()!.handleOpenURL(url, sourceApplication: sourceApplication ?? "") ?? false
}
}
另一方面,我将 FIRApp.configure()
放在 AppDelegate 类的“didFinishLaunchingWithOptions”函数中,并且我还分离了 FIRApp.configure()
out 作为 AppDelegate 类中的重写,如下所示。似乎没有任何帮助。我花了大约 4 天时间试图弄清楚这一点。为 Web 和 Android 实现它只花了几个小时。
override init() {
super.init()
FIRApp.configure()
//FIRDatabase.database().persistenceEnabled = true
}
最佳答案
我终于知道怎么做了!我创建了一个 video和 GIST展示如何去做,但我也会尝试在这里展示它。
首先,我将 Xcode 更新到版本 8,方法是单击“Apple App Store”,找到 Xcode,然后单击“更新”。下载需要一些时间。
其次,我通过在“didFinishLaunchingWithOptions”函数中添加 FIRApp.configure()
来更新 AppDelegate.swift。
第三,我将以下代码添加到我的 AppDelegate.swift 文件中:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return handled || GIDSignIn.sharedInstance().handle(
url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
第四,我将我的 ViewController.swift 文件更新为这个(确保输入你自己的 Facebook 密码):
// ViewController.swift
// Bizzy Books
//
// Created by Brad Caldwell on 9/23/16.
// Copyright © 2016 Caldwell Contracting LLC. All rights reserved.
//
import UIKit
import Firebase
import FirebaseAuthUI
import FirebaseDatabaseUI
import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI
import FBSDKCoreKit
import FBSDKLoginKit
class ViewController: UIViewController, FIRAuthUIDelegate {
//var db = FIRDatabaseReference.init()
var kFacebookAppID = "PLACE YOUR 16-DIGIT FACEBOOK SECRET HERE (FOUND IN FIREBASE CONSOLE UNDER AUTHENTICATION)"
override func viewDidLoad() {
super.viewDidLoad()
//FIRApp.configure()
checkLoggedIn()
}
func checkLoggedIn() {
FIRAuth.auth()?.addStateDidChangeListener { auth, user in
if user != nil {
// User is signed in.
} else {
// No user is signed in.
self.login()
}
}
}
func login() {
let authUI = FIRAuthUI.init(auth: FIRAuth.auth()!)
let options = FIRApp.defaultApp()?.options
let clientId = options?.clientID
let googleProvider = FIRGoogleAuthUI(clientID: clientId!)
let facebookProvider = FIRFacebookAuthUI(appID: kFacebookAppID)
authUI?.delegate = self
authUI?.providers = [googleProvider, facebookProvider]
let authViewController = authUI?.authViewController()
self.present(authViewController!, animated: true, completion: nil)
}
@IBAction func logoutUser(_ sender: AnyObject) {
try! FIRAuth.auth()!.signOut()
}
func authUI(_ authUI: FIRAuthUI, didSignInWith user: FIRUser?, error: Error?) {
if error != nil {
//Problem signing in
login()
}else {
//User is in! Here is where we code after signing in
}
}
func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionUniversalLinksOnly] as! String
return FIRAuthUI.default()!.handleOpen(url as URL, sourceApplication: sourceApplication )
}
}
第五,我向我的 Info.plist 添加了几个代码块(您需要自定义 Facebook 和 Google 代码 - 请参阅 Jacob Sikorski's guide 了解更多信息。
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.PLACE YOUR LONG CODE HERE ***(mine is 12 digits followed by a dash followed by 32 alpha-numeric characters)***</string>
<string>PLACE YOUR FACEBOOK CODE HERE ***(mine said fb followed by 16 numbers)***</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
应该是这样的。如果您有任何问题,请告诉我!
关于ios - 在 iOS (Swift) 上安装 FirebaseUI 的代码是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39417990/
我的代码有问题。我正在用 ReactJS 构建一个包含 3 个选项卡的单页网络应用程序。 当用户转到一个选项卡时,应该会显示来自 FirebaseUI 的身份验证表单。问题是它只在第一次和第二次工作,
我正在尝试实现 Firebase 身份验证。使用提供的用户界面, 我不知道单击“取消”按钮时调用了什么方法。似乎没有记录,https://github.com/firebase/firebaseui-
我在使用 FirebaseUI 时遇到问题。问题是,它会在启动时启动电子邮件登录流程,而无需单击任何内容。我希望它显示不同的登录选项,但它一直在启动电子邮件登录流程。我想让它显示这个: image 但
我正在使用firebaseui-web-react。在注册流程中,我想在创建用户之前验证用户提供的 displayName。特别是,我想确保 displayName 是唯一的。 我知道如何使用 Fir
我使用 FirebaseUI 进行登录。无论我如何尝试,我都无法使登录屏幕保持纵向模式。我在这里做错了什么?我怀疑这是 list 中的内容。 有趣的是,启动屏幕保持纵向模式,然后立即进入横向模式。我找
我已经创建了用于身份验证的自定义布局,但未显示该布局,而是显示了电子邮件登录屏幕 val customLayout = AuthMethodPickerLayout.Builder(R.layout.
这个问题已经有答案了: How can I detect if user first time in Firebase [duplicate] (4 个回答) 已关闭 3 年前。 我有一个 Andro
我想在我的项目中实现 FirebaseUI,但登录页面未显示任何输入字段或按钮: 显示FUIAuth的代码: @IBAction func logInButtonTapped(_ sender: An
我正在使用 FirebaseUI Android 用户使用以下代码登录: startActivityForResult( AuthUI.getInstance().c
我不太明白 recyclerView 和 glide 在缓存信息和图像数据方面是如何工作的,所以我想知道是否有人可以提供帮助。 目前,我将有关图像的元数据存储在实时数据库中。元数据有足够的信息可以进行
在我最近访问 Firestore 之后,我尝试使用 Firebase-UI 的 RecyclerView,但我找不到将新元素添加到特定位置的方法。 这是我对基本 RecyclerView 的处理方式:
我想使用 FirebaseUI RecyclerView。 我目前的应用程序(build.gradle)如下: implementation 'com.android.support:appc
我正在学习我在 Firebase (Udacity) 中的第一门类(class),并且有看起来像这样实现 Firebase Auth 的代码 private FirebaseAuth mFirebas
我正在使用 FirebaseUI 数据库使用 FirebaseListAdapter 从 ListView(在 ListFragment 上)的 Firebase 数据库引用中检索对象列表。我在 bu
我正在尝试为我的网站实现强制登录。我遇到的问题是我找不到这样做的方法。假设我创建了一个登录页面,例如... var uiConfig = { signInSuccessUrl: '',
我目前正从 Android 开发转向使用 Firebase 的 Swift 开发。 在 Android 中,很容易将 Firebase 检索到的快照解析为对象(例如 dataSnapshot.getv
按照 here 指南,我正在尝试将 Apple 登录添加到我的 iOS 应用程序。我已经使用这种方法成功实现了谷歌登录,但 Apple 似乎无法正常工作。我可以到达它要求我的苹果密码的地步,但它只是继
我正在使用 FirebaseUI for Web — 身份验证小部件来简化身份验证工作流程,但我遇到了一个问题。第一次一切正常。但是,在我登录后,小部件内容会清除,并且“使用...登录”按钮再也不会出
我有一个 JS 文件,我正在尝试使用 Firebase。 这是导致问题的部分(特别是 firebaseUI) var firebase = require('firebase'); var fireb
我正在努力解决一些看起来小菜一碟的问题,但我仍然无法找到解决方案。 我正在使用reactjs和firebaseUI web react实现firebase身份验证过程。一切都很好,除了当我尝试使用电子
我是一名优秀的程序员,十分优秀!