0

I have a function that will sync iCloud and I will be calling it from several view controllers. I want to have it display an alert if iCloud isn't available (either it was always off or the user signed out since the last visit, whatever). Would there be a way to add the alert code inside the function and have it display inside the VC the function is called inside?

func synciCloud(){

    if iCloudIsAvailable() {
        // stuff to sync iCloud
    } else {
        // where I'd like to call the alert
    }

}

Then later:

class List: UIViewController {
    override func viewDidLoad() {
        synciCloud()
        // this won't actually run on viewDidLoad but I'm just showing an example.
    }
}

So would there be a way to achieve this or am I thinking about it all wrong? Thank you.

CristianMoisei
  • 2,071
  • 2
  • 22
  • 28
  • You already try to present the alertViewController with? `UIApplication.shared.keyWindow?.rootViewController?.present(YourAlertViewController, animated: true, completion: nil)` – Rey Bruno Sep 06 '19 at 19:19
  • Also, this answer maybe can help you: https://stackoverflow.com/a/26735981/10687271 – Rey Bruno Sep 06 '19 at 19:26
  • 1
    @ReyBruno Your first comment doesn’t work if the root view controller already has a presented controller. – rmaddy Sep 06 '19 at 19:50

0 Answers0