I create a subscription to create and update. Creation always works great, and I get push notifications from other devices. The update is in iCloud, you can see them there, but push notifications are not delivered to the device.
- (void)subscribeWithType:(NSString*)type completionHandler:(void(^)(CKSubscription *))completionHandler { if (self.enabled == NO || _available == NO || _reachability.currentReachabilityStatus != ReachableViaWiFi) { if (completionHandler) { dispatch_async(dispatch_get_main_queue(), ^{ completionHandler(nil); }); } return; } NSPredicate *truePredicate = [NSPredicate predicateWithValue:YES]; CKSubscriptionOptions options = CKSubscriptionOptionsFiresOnRecordCreation | CKSubscriptionOptionsFiresOnRecordUpdate; CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:type predicate:truePredicate subscriptionID:[CTUtils GetUUID] options:options]; CKNotificationInfo *notification = [[CKNotificationInfo alloc] init]; notification.shouldSendContentAvailable = YES; notification.alertLocalizationKey = @""; notification.shouldBadge = NO; subscription.notificationInfo = notification; CKModifySubscriptionsOperation *operation = [[CKModifySubscriptionsOperation alloc] initWithSubscriptionsToSave:@[subscription] subscriptionIDsToDelete:nil]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); __block CKSubscription *resultSubscription = nil; operation.modifySubscriptionsCompletionBlock = ^(NSArray *savedSubscriptions, NSArray *deletedSubscriptionIDs, NSError *operationError) { if (operationError) { if (iCloudLog) { NSLog(@"create %@ subscriptions error : %@", type, operationError); } } else { resultSubscription = savedSubscriptions.firstObject; if (iCloudLog) { NSLog(@"created subscription for %@: %@", type, savedSubscriptions); } } dispatch_semaphore_signal(semapthore); }; dispatch_async(dispatch_get_main_queue(), ^{ [self.privateDatabase addOperation:operation]; }); dispatch_time_t time = DISPATCH_TIME_FOREVER; dispatch_semaphore_wait(semapthore, time); if (completionHandler) { dispatch_async(dispatch_get_main_queue(), ^{ completionHandler(resultSubscription); }); } }
Does anyone see an error here or why didn’t they implement push notification for updating?
source share