Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i add a popup that is invoked from my appdelegate class in swift?

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?

like image 923
user3766930 Avatar asked Oct 14 '25 11:10

user3766930


1 Answers

In Swift 3

self.window?.rootViewController?.present(alert, animated: true, completion: nil)
like image 133
Imtee Avatar answered Oct 17 '25 03:10

Imtee