Ich verwende CloudKit zum Speichern von Benutzerdaten und möchte Push-Benachrichtigungen erhalten, wenn die Datensätze geändert oder neue Datensätze erstellt werden. Aber es funktioniert nicht ...CloudKit Push Benachrichtigungen didReceiveRemoteNotification nie aufgerufen
I für die Abonnements registrieren wie folgt aus:
- (void) updateCloudSubscriptions {
NSPredicate *allPredicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
CKSubscription *newOrUpdateSubscription = [[CKSubscription alloc]
initWithRecordType:kMyRecordType predicate:allPredicate options:
(CKSubscriptionOptionsFiresOnRecordCreation | CKSubscriptionOptionsFiresOnRecordUpdate)];
CKNotificationInfo *newOrUpdateNotificationInfo = [CKNotificationInfo new];
newOrUpdateNotificationInfo.shouldBadge = NO;
newOrUpdateNotificationInfo.shouldSendContentAvailable = YES;
newOrUpdateSubscription.notificationInfo = newOrUpdateNotificationInfo;
CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:kMyContainerID]
publicCloudDatabase];
[publicDatabase saveSubscription:newOrUpdateSubscription
completionHandler:^(CKSubscription *theSubscription, NSError *saveError) {
if (saveError){
//error handling
}
NSLog(@"Subscription created");
}];
}
Dies gelingt. Auf dem CloudKit Dashboard wird das Abonnement ordnungsgemäß erstellt.
In meinem AppDelegate Ich habe nun folgendes:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeNone | UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:notificationSettings];
[application registerForRemoteNotifications];
}
und diese Delegatmethoden umgesetzt:
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"%@ with token = %@", NSStringFromSelector(_cmd), deviceToken);
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"%@ with error = %@", NSStringFromSelector(_cmd), error);
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"%@", NSStringFromSelector(_cmd));
}
didRegisterForRemoteNotificationsWithDeviceToken
erfolgreich mit einem Token genannt. Aber didReceiveRemoteNotification
wird nie aufgerufen.
Ich habe dies getestet, indem ich Werte auf der Mac-Version meiner App und auf der iPhone-Version geändert habe. Beide laden die Änderungen hoch, lösen jedoch keine Benachrichtigung aus. Ich habe auch versucht, die Werte direkt auf dem Dashboard zu ändern, aber das hat auch keine Benachrichtigungen verursacht.
Was fehlt mir hier?
Falls relevant: Ich bin auf OS X 10.10 mit XCode 6.4
I apsd
Protokollierung aktiviert, aber nur Nachrichten wie diese:
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Saving database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Destroying database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Closed database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Reopening database
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Initializing database on thread: <NSThread: 0x7f8f1bf80dd0>{number = 55, name = (null)}
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling auto vacuum.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling WAL journal mode.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling Foreign Key support.
Derzeit gibt es einen CloudKit Bug mit Update-Benachrichtigungen. Hast du deine App mit einem neuen Datensatz getestet? Weitere Informationen über den Update-Fehler finden Sie unter https://forums.developer.apple.com/thread/7288 –
@EdwinVermeer, das ist interessant. Ich erhalte jedoch auch keine Benachrichtigungen zur Erstellung von Datensätzen. – codingFriend1
Haben Sie in den Zielanwendungsfunktionen die Hintergrundmodi für Remote-Benachrichtigungen aktiviert? –