Where to find a clear explanation about swift alert (UIAlertController)?

后端 未结 3 1573
温柔的废话
温柔的废话 2021-01-31 19:01

Couldn\'t find a clear and informative explanation for this.

3条回答
  •  日久生厌
    2021-01-31 19:54

    Some of the syntax has changed since the original responses. Here is some sample code that alerts the user if they are not signed in to iCloud.

    CKContainer.default().accountStatus { (accountStatus, error) in
            switch accountStatus {
            case .available:
                print("iCloud Available")
            case .noAccount:
                print("No iCloud account")
                //simple alert dialog
                let alert=UIAlertController(title: "Sign in to iCloud", message: "This application requires iClound. Sign in to your iCloud account to write records. On the Home screen, launch Settings, tap iCloud, and enter your Apple ID. Turn iCloud Drive on. If you don't have an iCloud account, tap Create a new Apple ID", preferredStyle: UIAlertControllerStyle.alert);
                //no event handler (just close dialog box)
                alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil));
                //show it
                self.present(alert, animated: true, completion: nil)
            case .restricted:
                print("iCloud restricted")
            case .couldNotDetermine:
                print("Unable to determine iCloud status")
            }
        }
    

提交回复
热议问题