如何使用我的 Mac 应用程序中CKFetchNotificationChangesOperation
的订阅者处理和引导所有错过的通知CKSubscription
?- (void)application:(nonnull NSApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
我对该方法的代码如下,
- (void)application:(nonnull NSApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
NSLog(@"CKSubscription received.");
CKQueryNotification *cloudKitNotification = [CKQueryNotification notificationFromRemoteNotificationDictionary:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CloudKitUpdated" object:nil userInfo:@{@"ckNotification" : cloudKitNotification}];
}
我的应用程序是一个菜单,我希望它检查任何错过的通知并在单击菜单时正确处理它们。
更新:这是我一直在尝试的代码,但数组始终为空且没有错误。我正在通过运行应用程序、关闭应用程序、删除记录然后再次运行应用程序来进行测试。
NSMutableArray *array = [NSMutableArray array];
CKFetchNotificationChangesOperation *operation = [[CKFetchNotificationChangesOperation alloc] initWithPreviousServerChangeToken:nil];
operation.notificationChangedBlock = ^(CKNotification *notification) {
[array addObject:notification.notificationID];
};
operation.completionBlock = ^{
};
operation.fetchNotificationChangesCompletionBlock = ^(CKServerChangeToken *token, NSError *error) {
NSLog(@"Missed notifications: %@", array);
};
[_myContainer addOperation:operation];