我想要什麼不叫:didReceiveRemoteNotification當CloudKit記錄添加
我希望我的iOS應用程序來執行一旦CloudKit記錄添加一個動作。
我做了什麼:
我跟着蘋果的info做到這一點。
問題:
application:didReceiveRemoteNotification
永遠不會被調用。
我試圖解決這個問題:
我已經成功地建立了一個訂閱時加入CloudKit記錄得到通知。我確認這與application:didRegisterForRemoteNotificationsWithDeviceToken
。
我也證實了這個記錄確實是創建的。
我可以使用CKQueryOperation
獲取記錄。
我也試過用application:didReceiveRemoteNotification:fetchCompletionHandler
,但是這個方法也沒有被調用。
我搜索了Apple Developer Forums以及StackOverflow,但沒有找到解決我的問題的方法。
我該怎麼辦?
代碼來創建訂閱:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:@"command" predicate:predicate options:CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.alertLocalizationKey = @"New command.";
notificationInfo.shouldBadge = YES;
subscription.notificationInfo = notificationInfo;
[VMKGlobalVariables.GLOBAL_appDelegate.privateDatabase saveSubscription:subscription
completionHandler:^(CKSubscription *subscription, NSError *error) {
if (error)
{
// insert error handling
}
else
{
DDLogVerbose(@"Added command subscription successfully.");
}
}
];
遠程通知不適用於模擬器。您需要使用真實的設備。是這樣嗎? – Starlord
謝謝。是的,我使用的是iPhone 6s。 – vomako
更新您的問題,提供有關訂閱和添加記錄的更多相關信息。並確認您正在討論在一臺設備上添加記錄並在另一臺設備上獲取通知。您不會在用於添加記錄的相同設備上收到通知。 – rmaddy