这是苹果文档中的一句话:
“如果未配置 iCloud,请询问用户是否要配置它(如果要配置 iCloud,最好将他们转移到启动设置)。”
如何检查 iCloud 是否已配置以及如何启动 iCloud 设置?
Edit:
如果您的目标是 iOS6 或更高版本,您可以使用[[NSFileManager defaultManager] ubiquityIdentityToken];
。使用示例请参考@Dj S 的回答 https://stackoverflow.com/a/23557492/149008 :).
它比针对 iOS5 及更高版本的用户的原始解决方案更快、更简单
原答案
如记录在iOS 应用程序编程指南 - iCloud 存储 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html#//apple_ref/occ/instm/NSFileManager/URLForUbiquityContainerIdentifier:。可以通过向文件管理器询问普遍存在的容器 URL 来检查:)
只要您提供有效的普遍容器标识符,下面的方法就应该返回 YES
- (BOOL) isICloudAvailable
{
// Make sure a correct Ubiquity Container Identifier is passed
NSURL *ubiquityURL = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:@"ABCDEFGHI0.com.acme.MyApp"];
return ubiquityURL ? YES : NO;
}
然而,我发现URLForUbiquityContainerIdentifier:
第一次在会话中可能需要几秒钟(我在 iOS5 中使用它,所以现在情况可能有所不同)。我记得使用过这样的东西:
dispatch_queue_t backgroundQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(backgroundQueue,^{
BOOL isAvailable = [self isICloudAvailable]
/* change to the main queue if you want to do something with the UI. For example: */
dispatch_async(dispatch_get_main_queue(),^{
if (!isAvailable){
/* inform the user */
UIAlertView *alert = [[UIAlertView alloc] init...]
[alert show];
[alert release];
}
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)