購読しているCKFetchNotificationChangesOperation
からの見逃したすべての通知を処理し、Mac アプリケーションで に転送するにはどうすればよいですか? そのメソッドのコードは次のとおりです。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];