Die Informationen du hast gegeben, ist zu wenig. Aber stellen Sie sicher, dass Sie diese Dinge getan haben.
Sie sollten URL-Schemas wie in der folgenden Abbildung hinzugefügt haben.
In Ihrem AppDelegate Klasse stellen Sie sicher, haben Sie die folgende Funktion
//this function is added only
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
Und für Viewcontroller hinzugefügt oder in dem Sie die Schaltfläche hinzugefügt haben, den Code wie folgt
Import UIKit Import sein sollte Google importieren GoogleSignIn
Klasse ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDe Legat {
//label to display name of logged in user
@IBOutlet weak var labelUserEmail: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
//error object
var error : NSError?
//setting the error
GGLContext.sharedInstance().configureWithError(&error)
//if any error stop execution and print error
if error != nil{
print(error ?? "google error")
return
}
//adding the delegates
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
//getting the signin button and adding it to view
let googleSignInButton = GIDSignInButton()
googleSignInButton.center = view.center
view.addSubview(googleSignInButton)
}
//when the signin complets
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
//if any error stop and print the error
if error != nil{
print(error ?? "google error")
return
}
//if success display the email on label
labelUserEmail.text = user.profile.email
}
}
Es sollte 3.
Referenz mit Swift auf diese Weise arbeiten: Google Sign In Integration with Swift 3
Danke für den Rat. Ich habe den Breakpoint "All Exceptions" deaktiviert und festgestellt, dass ich ein Problem mit der Google Id hatte (einige Missverständnisse zwischen Programmierern verschiedener Plattformen). Ich werde jetzt prüfen, ob es mit der neuen ID richtig funktioniert. – Susana