如何确定何时删除CloudKit订阅? [英] How to find out when a CloudKit Subscription is deleted?

查看:146
本文介绍了如何确定何时删除CloudKit订阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS应用程序中使用CloudKit.

I am using CloudKit in my iOS application.

在我的应用程序中,每当用户修改某些数据时,我都会更新CloudKit私有数据库,以便用户的其他设备也能得到更新.

In my application, whenever user modifies some data, I update the CloudKit private db so that other devices of the user can also get updated.

此同步机制可以由用户启用/禁用.

This syncing mechanism can be enabled/disabled by the user.

当用户启用同步时,我创建一个订阅并将本地数据推送到CloudKit.

When user enables syncing, I create a subscription and push the local data to CloudKit.

如果用户已登录到其他设备,他们将开始按预期方式获得有关私有数据库更改的远程通知.

If the user has logged on to other devices, they start getting remote notifications about changes to the private database as expected.

应用程序显示UISwitch供用户启用/禁用同步.

The application shows a UISwitch for the user to enable/disable syncing.

让我们假设用户有2个设备DeviceADeviceB,它们显示通过将UISwitch.isOn设置为true启用了同步.

Let us assume the user has 2 devices DeviceA and DeviceB which show that syncing has been enabled by setting UISwitch.isOn to true.

如果用户在DeviceA上禁用了同步,则订阅将被删除,并且在DeviceA上进行的更改不会触发到DeviceB的远程通知.

If the user disables syncing on DeviceA, then the subscription is deleted and changes made on DeviceA do not trigger remote notifications to DeviceB as expected.

但是DeviceB仍然显示已启用同步.

But DeviceB still shows that syncing has been enabled.

是否有办法知道何时删除订阅?

Is there a way to know when a subscription has been deleted?

我了解 CKFetchSubscriptionsOperation .我可以定期调用CKFetchSubscriptionsOperation来了解订阅.有更好的方法吗?.

I know about CKFetchSubscriptionsOperation. I can call the CKFetchSubscriptionsOperation periodically to know about the subscriptions. Is there a better way to this?.

推荐答案

这是一个重大问题,也是我遇到的一个问题.你是对的.知道订阅状态的唯一方法是查询CKFetchSubscriptionsOperation可用的内容.

This is a great question and is something I ran in to as well. You are correct. The only way to know the status of a subscription is to query for what's available with CKFetchSubscriptionsOperation.

一种可能的解决方法是创建一个名为Subscription之类的recordType并将用户当前正在使用的subscriptionID s保存为常规CloudKit记录(只需使用String属性在CKRecord上.

One possible workaround is to create a recordType called something like Subscription and save the subscriptionIDs the user is currently using as regular CloudKit records (just use a String property on a CKRecord).

然后,当他们取消订阅设备时,您可以更新Subscription记录,其所有设备都将收到有关更改的通知.然后,该应用将根据用户可用的subscriptionID更新实际订阅.

Then when they unsubscribe on a device, you can update the Subscription record and all their devices will get notified of the change. The app would then update the actual subscriptions based on the subscriptionIDs the user has available.

这是一个潜在的工作流程:

So here's a potential workflow:

  1. DeviceA取消订阅subscription1.
  2. DeviceASubscription表中删除subscriptionRecord1.
  3. DeviceA使用CKModifySubscriptionsOperation()删除实际的subscription1订阅.
  4. DeviceB收到通知,通知subscriptionRecord1已删除,并将同步UISwitch切换为关闭(我想您正在使用本地持久性方法(如数据库或UserDefaults)保存这些开关的状态).
  1. DeviceA unsubscribes from subscription1.
  2. DeviceA deletes subscriptionRecord1 from the Subscription table.
  3. DeviceA deletes the actual subscription1 subscription using CKModifySubscriptionsOperation().
  4. DeviceB gets notified that subscriptionRecord1 was deleted and flips the sync UISwitch to off (I presume you are saving the state of these switches with a local persistence method like a database or UserDefaults).

希望这会有所帮助.如果您有任何问题,请告诉我.

Hopefully that helps. Let me know if you have any questions.

这篇关于如何确定何时删除CloudKit订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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