How to receive cloudkit notifications about changes made on record shared with me? : <p>I have two icloud accounts (<strong>A</strong> and <strong>B</strong>) on two different devices. From one of them (<strong>A</strong>) I share ckrecord to another one (<strong>B</strong>) like this:</p>

<pre><code>let controller = UICloudSharingController { controller, preparationCompletionHandler in

    let share = CKShare(rootRecord: record)
    share[CKShareTitleKey] = "title" as CKRecordValue

    share[CKShareTypeKey] = "pl.blueworld.fieldservice" as CKRecordValue
    share.publicPermission = .readWrite

    let modifyOperation = CKModifyRecordsOperation(recordsToSave: [record, share], recordIDsToDelete: nil)
    modifyOperation.savePolicy = .ifServerRecordUnchanged
    modifyOperation.perRecordCompletionBlock = { record, error in
        print(error?.localizedDescription ?? "")
    }

    modifyOperation.modifyRecordsCompletionBlock = { records, recordIds, error in

        print(share.url)
        preparationCompletionHandler(share, CloudAssistant.shared.container, error)
    }

    CloudAssistant.shared.container.privateCloudDatabase.add(modifyOperation)
}

controller.delegate = self

UIViewController.top()?.present(controller, animated: true)
</code></pre>

<p>When second device (<strong>B</strong>) did accept cloudkit share I fetch record and subscribe for changes:</p>

<pre><code>func application(_ application: UIApplication, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShareMetadata) {

    let acceptSharesOperation = CKAcceptSharesOperation(shareMetadatas: [cloudKitShareMetadata])
    acceptSharesOperation.perShareCompletionBlock = { metadata, share, error in

        if let error = error {
            UIAlertController.show(withMessage: error.localizedDescription)
        } else {

            let operation = CKFetchRecordsOperation(recordIDs: [cloudKitShareMetadata.rootRecordID])
            operation.perRecordCompletionBlock = { record, _, error in

                if let error = error {
                    UIAlertController.show(withMessage: error.localizedDescription)
                } else if let record = record {
                    CloudAssistant.shared.save(records: [record], recordIDsToDelete: [])

                    let options: CKQuerySubscriptionOptions = [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion]
                    let territorySubscription = CKQuerySubscription(recordType: "Territory", predicate: NSPredicate(value: true), options: options)

                    let notificationInfo = CKNotificationInfo()
                    notificationInfo.shouldBadge = false
                    notificationInfo.shouldSendContentAvailable = true

                    territorySubscription.notificationInfo = notificationInfo

                    CloudAssistant.shared.sharedDatabase?.save(territorySubscription) { _, _ in }
                }
            }

            CloudAssistant.shared.container.sharedCloudDatabase.add(operation)
        }
    }
    acceptSharesOperation.qualityOfService = .userInteractive
    CKContainer(identifier: cloudKitShareMetadata.containerIdentifier).add(acceptSharesOperation)
}
</code></pre>

<p>Now from device <strong>A</strong> I <strong>sucessfully</strong> (I am sure about that, changes is saved in iCloud) perform an update on a record shared with others. But device <strong>B</strong> doesnt know about that, unless I fetch record manually once again.</p>

<p><strong>But from the other side, it works pretty well.</strong> </p>

<p>If I successfully perform an update on a record shared with me (on device <strong>B</strong>) then device <strong>A</strong> mnagically gets a notification about change and everything is fine. What makes the difference?</p>

<p>How to subscribe for changes on a records shared with me?</p>

<p>P.S when I will be able I will start a bount of 200 or even more for someone who will help me with this.</p>

<p>iOS 11, Swift 4, Xcode 9</p>
