I'm working on a google sign in tutorial to my ios app and there's a part when we cannot log in user to my app.
So far the code section in appDelegate.swift looks like:
guard error == nil && data != nil else {
// check for fundamental networking error
print("error=\(error)")
//lets put popup here that says cant connect to server
GIDSignIn.sharedInstance().signOut()
return
}
and now instead of printing the error I want to put the alert popup window. I tried to write there:
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
but then I'm getting the xcode error near self.presentViewController
saying that value of type AppDelegate has no member presentViewController
.
How can I display an alert popup in that case?
In Swift 3
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With