2

I am trying to use CKSubscription this way:

NSArray *events = @[@1,@2,@3];
NSInteger myValue = 100;

NSPredicate *predicate = [NSPredicate predicateWithFormat:
    @"(value > %@) AND (prev_value < %@) AND (event_type IN %@)",
    @(myValue), @(myValue), events];

CKSubscription *sub = [[CKSubscription alloc] initWithRecordType:@"TableName"
    predicate:predicate options:(CKSubscriptionOptionsFiresOnRecordCreation)];

[db saveSubscription:sub completionHandler:^(CKSubscription *s, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error.localizedDescription);
        return;
    }
    NSLog(@"Success!");
}];

This getting me error:

Error: Error saving record subscription with id 781FB482-C9C9-4DA5-8022-CFDB8006223A to server:
invalid attempt to set value type NUMBER_INT64 for field 'binding_0' for type
'_sub_trigger_sub_220b17724b5262b0590a3c9d66be9826', defined to be: INT64_LIST

This looks like valid NSPredicate can not be properly stored in CloudKit as part of CKSubscription object. It that real Apple bug or mine?

P.S. I have tried a lot of different combinations by removing different parts of predicate condition. Looks like the only condition for event_type works fine, but when I am mixing 3 conditions with AND - this causes a problem.

P.P.S. I am using Xcode 6 beta 6 on OSX 10.10 DP6 and iOS8 beta 5 on iPhone 5S

UPDATE:

Subscriptions with one of the following predicates works fine:

NSPredicate *predicate1 = [NSPredicate predicateWithFormat:
    @"(value > %@) AND (prev_value < %@)", @(myValue), @(myValue)];

NSPredicate *predicate2 = [NSPredicate predicateWithFormat:
    @"(event_type IN %@)", events];

But saving subscription with common predicate fails:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
    @"(value > %@) AND (prev_value < %@) AND (event_type IN %@)",
    @(myValue), @(myValue), events];

Looks like real Apple CloudKit bug. Just opened issue at bugreport.apple.com #18105879

UPDATE 2:

Thanks to @purrrminator - here are two radars with problem with receiving CloudKit push notifications:

http://openradar.appspot.com/18807663

http://openradar.appspot.com/18798061

I found workaround for saving CKSubscription properly via presenting IN condition with a lot of equality comparers. But really I got no push notifications from CLoudKit...

k06a
  • 17,755
  • 10
  • 70
  • 110
  • All these fields: `value`, `prev_value` and `event_type` are `Int64`. – k06a Aug 22 '14 at 09:00
  • Are these actual failing values in myValue & events? – Ben Lachman Aug 23 '14 at 03:31
  • @BenLachman actual myValue is 1022, and events are @[@1,@2,@3]. – k06a Aug 23 '14 at 04:25
  • I have problem too creating compound predicate with more conditions, it seems CloudKit stores it inconsistently, you can try fetch subscriptions and print out all subpredicate to see, it was what you have originally saved, my issue: http://openradar.io/18549283 btw do you have any progress since then? – János Oct 05 '14 at 14:35
  • @János I have created issue on bugreport.apple.com, once Apple asked for my iCloud logs - I sent logs. Now I am waiting for fixing it :) – k06a Oct 05 '14 at 14:37
  • you could report your issue after bugreport on `openradar` too, then outsiders like me could read it too – János Oct 05 '14 at 14:38
  • get logs you mean `println("\(error.localizedDescription)")`? or is it any other way to investigate how iCloud works? – János Oct 05 '14 at 14:40
  • 2
    there is so few experts to ask and especially `CKSubscription` is kind of a buggy, hard to move on – János Oct 05 '14 at 14:43
  • @János I installed special provisioning profile, play my error and exported iCloud logs from iOS. Apple sent me provisioning profile, instruction and notice about NDA :) – k06a Oct 05 '14 at 14:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62483/discussion-between-k06a-and-janos). – k06a Oct 05 '14 at 14:45
  • Check this one too http://openradar.appspot.com/18807663, oh and this one http://openradar.appspot.com/18798061 . I've already cursed the CloudKit. The predicates are such undocumented and restricted in compare to core data ones. – kas-kad Oct 29 '14 at 08:07
  • I confirm that CKSubscription doesnt work with compound predicates in some cases. – kas-kad Oct 29 '14 at 08:15
  • @k06a can you update your question adding some recently mentioned radars here in comments section? – kas-kad Oct 29 '14 at 08:17
  • @purrrminator I'll add mention and some workaround – k06a Oct 29 '14 at 08:18
  • my compound predicate start to working after I changed the format from this `field1 == %@ && field2 == %@` to `(field1 == %@) AND (field2 == %@)` – kas-kad Oct 29 '14 at 09:01
  • Maybe your predicate will work like this `@"((value > %@) AND (prev_value < %@)) AND (event_type IN %@)"` – kas-kad Oct 29 '14 at 09:03
  • Arrrggh. My predicate only working with `FiresOnRecordUpdate` option. Not working with `FiresOnRecordDeletion`. Damn! – kas-kad Oct 29 '14 at 12:57
  • ^ fixed with this answer http://stackoverflow.com/questions/25822019/observe-ckrecord-deletion-via-cksubscription-does-not-work – kas-kad Oct 29 '14 at 15:34

1 Answers1

0

Try to create a CKNotification object, add it to the subscription before you add the subscription to the database. Also make sure you inspect all of the delegate methods related to the remote notification including the didFailToRegisterForRemoteNotificationsWithError. Regarding the predicate issue, I'd recommend trying out NSCompoundPredicate and a deeper review of the Predicates Programming Guide for other options.

Tommie C.
  • 12,895
  • 5
  • 82
  • 100