我创建了一个创建和更新订阅。创作总是很完美,我从其他设备获得推送通知。更新发送到iCloud,您可以在那里看到它们,但推送通知不会传送到设备。
- (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);
});
}
}
有人在这里看到错误或者为什么没有实现推送通知更新?