是否可以在“设置"中拦截 iCloud 开启/关闭 ->iCloud ->文件&数据? [英] Is it possible to intercept iCloud switching on/off in Settings -> iCloud -> Document & Data?

查看:15
本文介绍了是否可以在“设置"中拦截 iCloud 开启/关闭 ->iCloud ->文件&数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在设置 -> iCloud -> 文档& 下从打开到关闭iCloud支持是否可以拦截?数据?

Is it possible to intercept if the user switches from on to off the iCloud support under Settings -> iCloud -> Document & Data?

显然,当他这样做时,应用程序已经退出活动并进入后台.我的目标是 iOS7,我想保持 UIManagedDocument 同步,否则就像有两个不同的 UIDocuments:一个支持 iCloud,所有数据都创建,直到从打开切换到关闭和一个没有任何数据的新的.如果我在 iCloud 支持关闭时创建数据,然后我切换回开启,我会得到与支持关闭时相同的数据库.

Obviously when he does this the app has already resigned active and entered the background. I am targeting iOS7 and I would like to keep in sync the UIManagedDocument, otherwise it would be like having two different UIDocuments: one with iCloud support and all the data created until the switch from on to off and a new one without any data in it. If I create data when iCloud support has been switched to off, and then I switch back to on I get the same DB I had when the support has been switched to off.

注意:我相信 nelico 的回答是正确的.他写道:如果您的应用程序正在运行并且用户通过设置应用程序更改启用或禁用文档和数据 iCloud 同步,您的应用程序将收到 SIGKILL 信号."

Note: I believe nelico's answer is right. He wrote: "If your app is running and the user changes enables or disable Document & Data iCloud syncing via the settings app, your app will receive the SIGKILL signal."

当用户更改设置时,应用程序已经在后台并接收 SIGKILL 信号.这是我不明白和我不想要的.注册NSUbiquityIdentityDidChangeNotification 并不能解决这个问题.

When the user changes the settings the app is ALREADY in the background and receives the SIGKILL signal. This is what I do not understand and I do not want. Registering for NSUbiquityIdentityDidChangeNotification doesn't solve this problem.

推荐答案

另一种更简洁的解决方案是监听 NSUbiquityIdentityDidChangeNotification 通知,当您收到该通知时,检查 URLForUbiquityContainerIdentifier 如果它为空,则他们要么退出登录,要么关闭文档和数据".您还应该跟踪当前的无处不在令牌,以便您不仅可以知道他们是否已注销,还可以知道他们是否更改了 iCloud 帐户.发生这种情况的情况比人们想象的要多,因为 Apple Geniuses 喜欢在用户设备出现问题时创建一个新的 iCloud 帐户.

Another, cleaner, solution is to listen for the NSUbiquityIdentityDidChangeNotification notification and when you get that notification then check the URLForUbiquityContainerIdentifier if it is null they either signed out or turned off 'Documents and Data'. You should also be tracking the current ubiquity token so that you can know not only if they logged off but if they changed iCloud accounts. It happens more than one might think because Apple Geniuses like to just create a new iCloud account when things go wrong on users devices.

例如:

id <NSObject,NSCopying,NSCoding> _currentUbiquityIdentityToken;

...

_currentUbiquityIdentityToken = [[NSFileManager defaultManager] ubiquityIdentityToken];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (_iCloudAccountAvailabilityChanged:) name: NSUbiquityIdentityDidChangeNotification object: nil];

...

- (void)_iCloudAccountAvailabilityChanged:(NSNotification*)notif {
    if (![_currentUbiquityIdentityToken isEqual:[[NSFileManager defaultManager] ubiquityIdentityToken]]) {
        // Update the current token and rescan for documents.
        _currentUbiquityIdentityToken = [[NSFileManager defaultManager] ubiquityIdentityToken];
        // Do something about the change here...
    }
}

这篇关于是否可以在“设置"中拦截 iCloud 开启/关闭 ->iCloud ->文件&amp;数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆