FirebaseUI无法通过Facebook进行身份验证

时间:2018-07-20 11:01:37

标签: ios firebase-authentication facebook-login firebaseui

尝试通过FirebaseUI + Facebook进行身份验证时出现"This app is in development mode”错误。通过使该应用程序“对公众可用”来解决。之后,我得到另一个错误,显示为

  

”用户没有足够的权限来查看应用程序。   由于开发人员设置,用户无法查看此应用程序”

和日志

  

2018-07-20 17:56:30.610332 + 0700 SamuiPlus [79114:33415252] -canOpenURL:URL失败:“ fbauth2:/”-错误:“该操作无法完成。(OSStatus错误-10814 。)”   2018-07-20 17:56:30.610602 + 0700 SamuiPlus [79114:33415252]由于模拟器错误,回退到将访问令牌存储在NSUserDefaults中   2018-07-20 17:56:30.612003 + 0700 SamuiPlus [79114:33415252] -canOpenURL:URL失败:“ fbauth2:/”-错误:“操作无法完成。(OSStatus错误-10814。)”   2018-07-20 17:56:31.913536 + 0700 SamuiPlus [79114:33502682] TI​​C读取状态[12:0x0]:1:57   2018-07-20 17:56:31.913974 + 0700 SamuiPlus [79114:33502682] TI​​C读取状态[12:0x0]:1:57   2018-07-20 17:56:32.078459 + 0700 SamuiPlus [79114:33415252]信息:显示服务器已启动(协议版本43)。   2018-07-20 17:56:32.084358 + 0700 SamuiPlus [79114:33415252]无法在初始化期间成功更新网络信息。   2018-07-20 17:56:32.136652 + 0700 SamuiPlus [79114:33415252] [App]如果我们使用的是真正的预提交处理程序,则由于CA限制,我们实际上无法添加任何新的篱笆   2018-07-20 17:56:32.647304 + 0700 SamuiPlus [79114:33502692] TI​​C读取状态[13:0x0]:1:57   2018-07-20 17:56:32.647397 + 0700 SamuiPlus [79114:33502692] TI​​C读取状态[13:0x0]:1:57

我遵循了有关在我的应用中设置firebase和facebook的所有官方说明(info.plist,URL类型),尝试在developers.facebook.com上进行了不同的设置,但仍然不知道是什么原因引起的。 在Android版本的应用程序上,使用Facebook登录可以正常工作。

呈现AuthViewController

func showAuthUI(delegate: FUIAuthDelegate) {
    presentModalViewControllerDerivedFrom({ (_) -> UIViewController in
        let authUI = FUIAuth.defaultAuthUI()
        authUI?.delegate = delegate
        let authViewController = authUI!.authViewController()
        return authViewController
    }, animation: true, completion: nil)
}

FUIAuthDelegate

  extension ProfilePresenter: FUIAuthDelegate {

    func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?){
        if let error = error as NSError? {
            if let errorMessage = error.userInfo["NSLocalizedDescription"] as? String {
                //Show Alert with message provided in 'errorMessage'
                print("auth ui didSignInWith authDataResult, error: \(errorMessage)")
            } else {
                //Show General Alert
                print("auth ui didSignInWith authDataResult, general error")
            }
        } else if let user = authDataResult?.user {
            //Logged in
            // ...
        } else {
            // Unknow State
            print("auth ui didSignInWith authDataResult, unknown state")
        }
    }
}

AppDelegate

  override init() {
        super.init()
        FirebaseApp.configure()
        let authUI = FUIAuth.defaultAuthUI()
    }

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        let authUI = FUIAuth.defaultAuthUI()

        let providers: [FUIAuthProvider] = [
            FUIGoogleAuth(),
            FUIFacebookAuth(permissions: ["public_profile", "email"]),
            FUIPhoneAuth(authUI:FUIAuth.defaultAuthUI()!),
            ]
        authUI?.providers = providers

        return true
    }

  func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?
        if FUIAuth.defaultAuthUI()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
            return true
        }
        // other URL handling goes here.
        return false
    }

使用其他提供程序登录即可。 预先感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

我希望您创建facebook auth ID,而您只想放置此代码并从项目中的任何位置调用此函数。

在AppDelegate中

在applicationDidFinishLaunchingWithOptions

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

在UIApplicationOpenURLOptionsKey函数中

return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

然后为FacebookAuth.swift创建自定义类,并为facebookLogin创建函数。

    func faceBookLogin() {
      let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
      fbLoginManager.logIn(withReadPermissions: ["email"], from: 
      (self.senderController as! LoginViewController)) { (result, error) -> 
      Void in
      if (error == nil){
       let facebookLoginResult : FBSDKLoginManagerLoginResult = result!
       if (result?.isCancelled)!{
            return
        }
        if(facebookLoginResult.grantedPermissions.contains("email")){
            self.getFacebookUserData()
        }else{

        }
     }else{

        }
      }
  }

然后获取getFaceBookUserData()的获取Facebook用户数据创建功能,以获取Facebook用户数据。

func getFacebookUserData(){
        if((FBSDKAccessToken.current()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
                if (error == nil){
                    if let userData = result as? NSDictionary{
                        print(userData)
                     }
                }else{

                }
            })
        }
    }