应用程序在转换为swift 3语法后无法与Facebook和Firebase进行身份验证 [英] App could not authenticate with Facebook and Firebase after conversion to swift 3 syntax

查看:107
本文介绍了应用程序在转换为swift 3语法后无法与Facebook和Firebase进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我清理了我的项目,以消除所有的错误。应用程序似乎启动,登录页面似乎工作,但是当我尝试登录到Facebook,这是会发生什么:

  TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE响应状态就绪和错误(null)
2016-09-15 12:36:50.254067 2 [3083:89230] [] tcp_connection_event_notify 12事件:TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE,原因:nw_connection事件应该传递:true
2016-09-15 12:36:50.254511 2 [3083:89230] [] tcp_connection_get_statistics DNS:从启动以来,3ms / 7ms,TCP:自启动以来就有61ms / 76ms,TLS:99ms / 172ms,起始
2016- 09-15 12:36:50.492341 2 [3083:89140] [] tcp_connection_cancel 12
2016-09-15 12:36:50.493012 2 [3083:88773] [] nw_socket_handle_socket_event事件掩码:0x4
2016 -09-15 12:36:50.493506 2 [3083:88773] [] nw_socket_handle_socket_event Socket收到WRITE_CLOSE事件
2016-09-15 12:36:50.494087 2 [3083:88773] [] nw_endpoint_handler_cancel [12 graph.facebook .com:443就绪解析器(满意)]
2016-09-15 12:36:50.494691 2 [3083:88773] [] nw_endpoint_handler_cancel [12.1 31.13.78.13:443准备套接字流(满意)]
2016-09-15 12:36 :50.495482 2 [3083:88773] [] __nw_socket_service_writes_block_invoke sendmsg(fd 15,31 bytes):套接字已关闭
2016-09-15 12:36:50.495878 2 [3083:88773] [] nw_endpoint_flow_protocol_error [12.1 31.13 .78.13:443已取消socket-flow(null)] Socket协议发送错误:[32] Broken pipe
2016-09-15 12:36:50.496536 2 [3083:88773] [] nw_endpoint_flow_protocol_disconnected [12.1 31.13.78.13 :443已取消socket-flow(null)]输出协议断开
2016-09-15 12:36:50.496888 2 [3083:88773] [] nw_resolver_cancel_on_queue 0x6000003042f0
2016-09-15 12:36: 50.497285 2 [3083:88773] [] - [NWConcrete_tcp_connection dealloc] 12

这只是一个当我尝试登录时,输出的日志文件。



顺便说一下,我的代码是这样设置的,用于loginviewcontrol ler

  import UIKit 
import FBSDKLoginKit
import Firebase
import FirebaseAuth

class FacebookLoginViewController:UIViewController,FBSDKLoginButtonDelegate {

var loginButton:FBSDKLoginButton = FBSDKLoginButton()

覆盖func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从笔尖进行任何其他设置。
self.loginButton.center = self.view.center
self.loginButton.readPermissions = [public_profile,email,user_friends]
self.view!.addSubview(loginButton )
self.loginButton.delegate = self


FIRAuth.auth()?。addAuthStateDidChangeListener {auth,
中的用户,如果let user = user {
//用户已登录
self.performSegueWithIdentifier(loggedIn,sender:self)

}
}

}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理可以重新创建的任何资源。
}


func loginButton(loginButton:FBSDKLoginButton !, didCompleteWithResult result:FBSDKLoginManagerLoginResult !, error:NSError!){
print(user logged in)



if(error!= nil)
{
}

else if(result.isCancelled){

}

else {
//交换Facebook凭据以获取firebase凭据

允许凭据= FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken() .tokenString)

//登录firebase
FIRAuth.auth()?。signInWithCredential(credential){(user,error)in

self.performSegueWithIdentifier( loggedIn,发件人:self)
print(用户登录到firebase)
}
}

}

func loginButtonDidLogOut(loginButton:FBSDKLoginButton!){
print(user logged out)
}

}

这里是didFinishLaunchingWithOptions

  func应用程序(应用程序:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool {
FIRApp.configure()
//在应用程序启动后覆盖自定义点。
let navAppearance = UINavigationBar.appearance()
let tabAppearance = UITabBar.appearance()

let backImage = UIImage(命名为back)
navAppearance.backIndicatorImage = backImage
navAppearance.backIndicatorTransitionMaskImage = backImage


let lightBlackColour = UIColor(red:50 / 255.0,green:50 / 255.0,blue:54 / 255.0,alpha:1.0)
let lightYellowColour = UIColor(red:255 / 255.0,green:250 / 255.0,blue:36 / 255.0,alpha:1.0)

navAppearance.tintColor = lightYellowColour
navAppearance。 barTintColor = lightBlackColour //设置酒吧色调
navAppearance.titleTextAttributes = [NSForegroundColorAttributeName:lightYellowColour]

tabAppearance.barTintColor = lightBlackColour
tabAppearance.tintColor = lightYellowColour

let barButtonAppearance = UIBarButtonItem.appearance()
barButtonAppe aReg.setBackButtonTitlePositionAdjustment(UIOffsetMake(0,-60),forBarMetrics:.Default)
barButtonAppearance.setBackButtonTitlePositionAdjustment(UIOffsetMake(0,-60),forBarMetrics:.Compact)

UIApplication.sharedApplication ).statusBarStyle = .LightContent

FBSDKApplicationDelegate.sharedInstance()。应用程序(应用程序,didFinishLaunchingWithOptions:launchOptions)
返回true
}


解决方案

在我的应用程序中,Facebook和Google登录在iOS 10中不起作用。所以我已经开启了钥匙串共享有用。像





可能有帮助。告诉我,如果没有。


I've cleaned out my project to iron out all the errors. App seems to launch and the login page seems to work, but when I tried logging in to Facebook, this is what happens:

TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE in response to state ready and error (null)  
2016-09-15 12:36:50.254067 2[3083:89230] [] tcp_connection_event_notify 12 event: TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE, reason: nw_connection event, should deliver: true  
2016-09-15 12:36:50.254511 2[3083:89230] [] tcp_connection_get_statistics DNS: 3ms/7ms since start, TCP: 61ms/76ms since start, TLS: 99ms/172ms since start  
2016-09-15 12:36:50.492341 2[3083:89140] [] tcp_connection_cancel 12  
2016-09-15 12:36:50.493012 2[3083:88773] [] nw_socket_handle_socket_event Event mask: 0x4  
2016-09-15 12:36:50.493506 2[3083:88773] [] nw_socket_handle_socket_event Socket received WRITE_CLOSE event  
2016-09-15 12:36:50.494087 2[3083:88773] [] nw_endpoint_handler_cancel [12 graph.facebook.com:443 ready resolver (satisfied)]  
2016-09-15 12:36:50.494691 2[3083:88773] [] nw_endpoint_handler_cancel [12.1 31.13.78.13:443 ready socket-flow (satisfied)]  
2016-09-15 12:36:50.495482 2[3083:88773] [] __nw_socket_service_writes_block_invoke sendmsg(fd 15, 31 bytes): socket has been closed  
2016-09-15 12:36:50.495878 2[3083:88773] [] nw_endpoint_flow_protocol_error [12.1 31.13.78.13:443 cancelled socket-flow (null)] Socket protocol sent error: [32] Broken pipe  
2016-09-15 12:36:50.496536 2[3083:88773] [] nw_endpoint_flow_protocol_disconnected [12.1 31.13.78.13:443 cancelled socket-flow (null)] Output protocol disconnected  
2016-09-15 12:36:50.496888 2[3083:88773] [] nw_resolver_cancel_on_queue 0x6000003042f0  
2016-09-15 12:36:50.497285 2[3083:88773] [] -[NWConcrete_tcp_connection dealloc] 12

This is just a snippet of the log file of the output when I tried logging in.

By the way, my code is set up as such for the loginviewcontroller

import UIKit
import FBSDKLoginKit
import Firebase
import FirebaseAuth

class FacebookLoginViewController: UIViewController, FBSDKLoginButtonDelegate{

    var loginButton: FBSDKLoginButton = FBSDKLoginButton()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.loginButton.center = self.view.center
        self.loginButton.readPermissions = ["public_profile", "email", "user_friends"]
        self.view!.addSubview(loginButton)
        self.loginButton.delegate = self


        FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
            if let user = user {
                // User is signed in.
                self.performSegueWithIdentifier("loggedIn", sender: self)

            }
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        print("user logged in")



        if(error != nil)
        {
        }

        else if(result.isCancelled){

        }

        else{
        // Exchange facebook credential for a firebase credential

        let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)

        // Login to firebase
        FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in

            self.performSegueWithIdentifier("loggedIn", sender: self)
            print("user logged in to firebase")
            }
        }

    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        print("user logged out")
    }

}

here's the didFinishLaunchingWithOptions

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        FIRApp.configure()
        // Override point for customization after application launch.
        let navAppearance = UINavigationBar.appearance()
        let tabAppearance = UITabBar.appearance()

        let backImage = UIImage(named: "back")
        navAppearance.backIndicatorImage = backImage
        navAppearance.backIndicatorTransitionMaskImage = backImage


        let lightBlackColour = UIColor(red: 50/255.0, green: 50/255.0, blue: 54/255.0, alpha: 1.0)
        let lightYellowColour = UIColor(red: 255/255.0, green: 250/255.0, blue: 36/255.0, alpha: 1.0)

        navAppearance.tintColor = lightYellowColour
        navAppearance.barTintColor = lightBlackColour // Set the bar tint colour
        navAppearance.titleTextAttributes = [NSForegroundColorAttributeName: lightYellowColour]

        tabAppearance.barTintColor = lightBlackColour
        tabAppearance.tintColor = lightYellowColour

        let barButtonAppearance = UIBarButtonItem.appearance()
        barButtonAppearance.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)
        barButtonAppearance.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Compact)

        UIApplication.sharedApplication().statusBarStyle = .LightContent

        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }

解决方案

In My app also Facebook and Google Login not working in iOS 10. So I have made ON keychain sharing and it works. Like

It may help. Tell me if not.

这篇关于应用程序在转换为swift 3语法后无法与Facebook和Firebase进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆