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

查看:222
本文介绍了是否可以在设置 - > gtc中拦截iCloud交换开/关。 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 ,否则就像有两个不同的UID文档:一个与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的回答是正确的。他写道:如果您的应用正在运行,用户更改通过设置应用启用或禁用Document& Data 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."

当用户更改设置时,应用程序在后台ALREADY并接收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帐户。它发生多个人可能认为,因为苹果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...
    }
}

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

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