简体   繁体   中英

How to get iOS Google sign in using Firebase work on all iPhone Simulators?

I've implemented Google Sign in with Firebase on iOS with Swift. It works on these iPhone simulators(5,5S,6,6S,6S plus). It doesn't work on 6 plus only. No matter how many times I click the sign in button in my LoginViewController, the google sign in page doesn't open. Any thoughts as to why this might be the case?

Here is my AppDelegate.swift and LoginViewController.swift code.

//
//  AppDelegate.swift
// 
//
// 
//

import UIKit
import Firebase
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        FIRApp.configure()
        GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self
        return true
    }

    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        return GIDSignIn.sharedInstance().handleURL(url,
            sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
            annotation: options[UIApplicationOpenURLOptionsAnnotationKey])

    }

    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
        withError error: NSError!) {
            if let error = error {
                print(error.localizedDescription)
                return
            }
            let authentication = user.authentication
            let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
                accessToken: authentication.accessToken)


            FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
                // ...
            }
    }

    func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
        withError error: NSError!) {
            // Perform any operations when the user disconnects from app here.
            // ...
    }



    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}


//
//  ViewController.swift
//  
//
//  
//

import UIKit
import Firebase
import GoogleSignIn

class LogInViewController: UIViewController,GIDSignInUIDelegate {





    @IBOutlet weak var GoogleSignInButton: UIButton!

    @IBAction func Clicked(sender:  UIButton) {
         GIDSignIn.sharedInstance().uiDelegate = self
         GIDSignIn.sharedInstance().signIn();
    }


    override func viewDidLoad() {
        super.viewDidLoad()


        GIDSignIn.sharedInstance().uiDelegate = self

        // Uncomment to automatically sign in the user.


    // TODO(developer) Configure the sign-in button look/feel:
       //GIDSignIn.sharedInstance().signInSilently()



        // ...
        // Do any additional setup after loading the view, typically from a nib.
    }





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


}

Fixed. 6 plus emulator on my version of Xcode was blocking HTTP calls even though Firebase Analytics is enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM