How to parse a CKSubscription userinfo field returned in TVos in swift

176 views Asked by At

I have a CKSubscription running under TvOS that is returning this user info object, when the subscription fires, which is great. But how am I meant to parse this in Swift, surely not by crafting my own parsing routine?

userInfo [ck: {
ce = 2;
cid = "iCloud.blah";
nid = "be5a3f8d-blah-blah-blah-813544059695";
qry =     {
    dbs = 2;
    fo = 2;
    rid = "807524B0-blah-blah-blah-8E60519B6D56";
    sid = "037E27BA-blah-blah-blah-366959FF49DA";
    zid = "_defaultZone";
    zoid = "_defaultOwner";
};
}]

My question, somewhat basic forgive me. Interested in the rid, which is the RecordID.

Is no library to parse this information out? If I craft my own code; it will break in the next release of iOS.

1

There are 1 answers

0
user3069232 On

Sorry everyone; spend two hours looking, posted this; and then found the answer here.. an excellent post on the subject.

https://www.invasivecode.com/weblog/advanced-cloudkit-part-iii

Here is the code ...

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let notification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo as! [String : NSObject])
    let container = CKContainer.defaultContainer()
    let database = container.publicCloudDatabase

    if notification.notificationType == .Query {
        let queryNotification = notification as! CKQueryNotification
        if queryNotification.queryNotificationReason  == .RecordUpdated {
            print("queryNotification.recordID \(queryNotification.recordID)")
        }
    }
}

Posting it cause it was difficult to find and may be useful to others facing the same challenge in the future.