使用alertLocalizationArgs和/或desiredKeys时CKDatabaseSubscription成功失败

发布于 2025-01-18 15:36:15 字数 2185 浏览 2 评论 0原文

我正在使用核心数据 + CloudKit& amp; CloudKit共享。我试图在任何参与者向共享的更改发布时,向所有参与者介绍一个动态通知。

我正在尝试使用ckdatabasesubscription cksubscription.notificationinfo .alertlocalizationargsargs 和.desiredkeys以获取通缉来自CloudKit的信息。但是,当添加这两个参数中的任何一个或两个时,订阅并未将我的共享数据库订阅保存在CloudKit仪表板中。 - 无通知。

但是,如果您删除.AlerTlocalizationArgs.Desiredkeys,则订阅将在CloudKit仪表板中显示。 - 导致从.AlerTlocalizationkekey显示的通知

订阅:

func subscribeToSharedDBForRecordType() {

    let subscriptionID = "mySubscriptionID"
    let subscription = CKDatabaseSubscription(subscriptionID: subscriptionID)

    let recordType = "CD_MyRecordType"
    subscription.recordType = recordType

    let notificationInfo = CKSubscription.NotificationInfo()

    notificationInfo.alertLocalizationKey = "Localized String Key" // Value: "Localized String Key" = "Test: %@";
    notificationInfo.soundName = "default"

    // --- Adding `alertLocalizationArgs` and/or `desiredKeys` casues CKDatabaseSubscription to not show up in CloudKit
    // notificationInfo.alertLocalizationArgs = ["CD_myStringArgument1"]
    // notificationInfo.desiredKeys = ["CD_myStringArgument1"]


    notificationInfo.shouldSendContentAvailable = true

    subscription.notificationInfo = notificationInfo

    let operation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: nil)
    operation.modifySubscriptionsResultBlock = { result in
        print(#function, "modifySubscriptionsResultBlock:")
        switch result {
            case .success(let result):
                print(".success:", result)
            case .failure(let error):
                print(".failure:", error.localizedDescription)
        }
    }
    operation.qualityOfService = .utility

    let ckContainer: CKContainer = CKContainer(identifier: "myCKIdentifier")
    ckContainer.sharedCloudDatabase.add(operation)

    }

两个操作都返回成功的结果。

这是正确的行为吗?我很难理解为什么添加.DesiredKeys或.Alertlocalization Args导致订阅失败。

注意:我不能使用ckquerysubscription(在其中通知会正确触发,但仅适用于所有者),因为这是在共享数据库上。

I'm using Core Data + CloudKit && CloudKit Sharing. I'm trying to present a dynamic notification to all participants of a CKShare whenever any participant posts a change to the share.

I'm trying to use a CKDatabaseSubscription with CKSubscription.NotificationInfo of .alertLocalizationArgs and .desiredKeys to get the wanted information from CloudKit. However, when adding either or both of these parameters, The subscription is not saved to my Shared Database Subscriptions in CloudKit Dashboard. - Resulting in no notification.

But if you remove .alertLocalizationArgs and .desiredKeys, the subscription will show in CloudKit Dashboard. - Resulting in a notification being displayed from the .alertLocalizationKey.

The Subscription:

func subscribeToSharedDBForRecordType() {

    let subscriptionID = "mySubscriptionID"
    let subscription = CKDatabaseSubscription(subscriptionID: subscriptionID)

    let recordType = "CD_MyRecordType"
    subscription.recordType = recordType

    let notificationInfo = CKSubscription.NotificationInfo()

    notificationInfo.alertLocalizationKey = "Localized String Key" // Value: "Localized String Key" = "Test: %@";
    notificationInfo.soundName = "default"

    // --- Adding `alertLocalizationArgs` and/or `desiredKeys` casues CKDatabaseSubscription to not show up in CloudKit
    // notificationInfo.alertLocalizationArgs = ["CD_myStringArgument1"]
    // notificationInfo.desiredKeys = ["CD_myStringArgument1"]


    notificationInfo.shouldSendContentAvailable = true

    subscription.notificationInfo = notificationInfo

    let operation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: nil)
    operation.modifySubscriptionsResultBlock = { result in
        print(#function, "modifySubscriptionsResultBlock:")
        switch result {
            case .success(let result):
                print(".success:", result)
            case .failure(let error):
                print(".failure:", error.localizedDescription)
        }
    }
    operation.qualityOfService = .utility

    let ckContainer: CKContainer = CKContainer(identifier: "myCKIdentifier")
    ckContainer.sharedCloudDatabase.add(operation)

    }

Both operations return a successful Result.

Is this the correct behavior? I'm having trouble understanding why adding .desiredKeys or .alertLocalizationArgs is causing the subscription to fail.

Note: I can't use a CKQuerySubscription (where the notification would fire correctly, but only for the owner) because this is on the sharedDatabase.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文