0

When I access the recordFields on a CKQueryNotification returned from a subscription, I get this error:

Could not cast value of type '__NSCFDictionary' (0x1009f0630) to 'CKRecordValue' (0x1009fc050).

I process the notification like this:

let notification: CKNotification = CKNotification(fromRemoteNotificationDictionary: userInfo as! [String : NSObject])

It seems to work fine and I get a CKQueryNotification.

The notification recordFields prints out like:

<CKQueryNotification: 0x156ef2bf0; notificationType=1, notificationID=<CKNotificationID: 0x156ef41e0; UUID=ba82325d-ab9e-4805-bb26-994a1122900b>, containerIdentifier=iCloud.com.skyvalleystudio.RaceTiming, subscriptionID=Marks for 06597454-4EAD-434E-BC03-CE51D987C79F, queryNotificationReason=1, recordFields={
    location =     {
        altitude = 0;
        course = "-1";
        horizontalAccuracy = 0;
        latitude = "37.33296424";
        longitude = "-122.03937369";
        speed = "-1";
        timestamp = "484712160.263403";
        verticalAccuracy = "-1";
    };
    timeStamp = 484712160;
    user = "_2031e89e9ade8345c7d4248f3ec3a2e6";
}, recordID=<CKRecordID: 0x156ef1670; 568D257C-E849-4492-A810-CB7076FC5A22:(_defaultZone:__defaultOwner__)>, isPublicDatabase=1>

So it looks like the recordFields dictionary is there and populated. I try to access is like this:

let timestamp = notification.recordFields!["timeStamp"] as? NSDate

Then I get the error.

UPDATE I filed a Apple bug report 26251611.

The CLLocation is not being decoded in the CKNotification creation is my best guess.

One possible workaround is processing the userInfo directly, but I had problems with processing the CKReference. It seems like the CKRecordValue protocol adopters should be better handled when the CKNotification is created.

UPDATE Closed as duplicate of 24643471. It's still open at this time...

Yann Bodson
  • 1,634
  • 1
  • 17
  • 29
James
  • 851
  • 6
  • 10
  • FYI - There was a [recent question](http://stackoverflow.com/questions/37059790/accessing-recordfields-from-ckquerynotification-swift-2) with the same basic issue. Appears to be related to the `CLLocation` field. – rmaddy May 12 '16 at 03:22
  • It does seem to be related to the CLLocation. I removed it and don't get the crash. I still am not getting the result however, so I must not understand how to parse this. Is this a standard JSON format? – James May 12 '16 at 16:52
  • What I do is get the `CKRecordID` from the notification and then query the database for the record. – rmaddy May 12 '16 at 16:55
  • I filed a bug report. I was trying to be efficient by having the data I needed come in on the notification payload rather than having another round trip. I really think their CKRecordValue typing is not working or the `CKNotification(fromRemoteNotificationDictionary:)` is not completing its job. – James May 13 '16 at 02:59

0 Answers0