在iPhone中以编程方式从另一个应用程序打开iCloud设置

时间:2017-01-27 12:56:56

标签: ios objective-c iphone ios10

如果iPhone中没有启用iCloud,我必须从我的应用程序打开iCloud设置。

我非常感谢你的回答,我的意思是。

1 个答案:

答案 0 :(得分:0)

不幸的是,Apple没有提供这样做的方法。官方的iCloud设计指南有一个Alert the User to Enter iCloud Credentials部分,其中包含以下内容:

[[CKContainer defaultContainer] accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error) {
     if (accountStatus == CKAccountStatusNoAccount) {
         UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sign in to iCloud"
                                                                   message:@"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:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"Okay"
                                              style:UIAlertActionStyleCancel
                                            handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
    }
    else {
        // Insert your just-in-time schema code here
    }
}];

然而,在WWDC 2015 Session 715“CloudKit提示与技巧”中,他们提出了一种更微妙的方法starting about 7:30

  

我想谈谈几个最佳做法   在您的应用中处理丢失的帐户。这可能很诱人   遇到这种情况,为用户说出警报   他们没有登录iCloud帐户,无法继续。   这对用户没有帮助,因为他们可能会忽略警报   并重试一个操作,使他们看到第一个警报   地点。我们建议的是你优雅地降低你的   用户界面只是简单地禁用了您需要的应​​用功能   一个帐户,为此您现在可以使用CKAccount更改   通知重新启用该UI,当您收到它时,请重新检查   帐户状态,并查看现在有一个帐户可用。

这是参考iOS 9中引入的CKAccountChange通知。

可能不是你想要的答案,但希望这会有所帮助。

相关问题