问题描述
以下是来自Apple Docs的句子:
如果未配置iCloud,请询问用户是否要配置它(如果他们想要配置iCloud,最好将它们转移到启动设置)。
Here is the sentence from Apple Docs:"If iCloud is not configured, ask users if they want to configure it (and, preferably, transfer them to Launch Settings if they want to configure iCloud)."
如何检查是否配置了iCloud以及如何启动iCloud的设置?
How can I check if iCloud is configured or not and how to launch settings for iCloud?
推荐答案
编辑
如果您的目标是iOS6或更高版本,您可以使用 [[NSFileManager defaultManager] ubiquityIdentityToken];
。有关使用示例,请参阅 :)。
它比它更快更容易适用于iOS5及以上人群的原始解决方案
If you are targeting iOS6 or above you can use [[NSFileManager defaultManager] ubiquityIdentityToken];
. For usage example please refer @Dj S' answer :).
It is faster and easier than the original solution which was meant for people targeting iOS5 and above
原始答案
如。可以通过向文件管理器询问ubiquity容器URL来检查:)
Original Answer
As documented in iOS App programming guide - iCloud Storage. That can be checked by asking the ubiquity container URL to the file manager :)
只要你提供一个有效的普遍容器标识符,方法就应该返回YES
As long as you supply a valid ubiquity container identifier below method should return 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中使用它,所以现在可能会有所不同)。我记得使用过这样的东西:
However, I've found that URLForUbiquityContainerIdentifier:
might take several seconds the very first time within a session (I used it in iOS5 so things might be different now). I remember using something like this:
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];
}
});
});
这篇关于如何检查iCloud是否以编程方式配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!