CKDatabaseSubscription fails successfully when using alertLocalizationArgs and/or desiredKeys

219 views Asked by At

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.

0

There are 0 answers