使用alertLocalizationArgs和/或desiredKeys时CKDatabaseSubscription成功失败
我正在使用核心数据 + 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论