2016-06-12 55 views
0

我想要什麼不叫: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."); 
         } 
        } 

    ]; 
+0

遠程通知不適用於模擬器。您需要使用真實的設備。是這樣嗎? – Starlord

+0

謝謝。是的,我使用的是iPhone 6s。 – vomako

+0

更新您的問題,提供有關訂閱和添加記錄的更多相關信息。並確認您正在討論在一臺設備上添加記錄並在另一臺設備上獲取通知。您不會在用於添加記錄的相同設備上收到通知。 – rmaddy

回答

0

你已經註冊你行應用程序委託。

application.registerForRemoteNotifications() 

在應用程序委託中是否有一些代碼看起來像這樣?

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    let notification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo as! [String : NSObject]) 

    let container = CKContainer(identifier: "iCloud.blah.com") 
    let publicDB = container.publicCloudDatabase 

    if notification.notificationType == .Query { 
     let queryNotification = notification as! CKQueryNotification 
     if queryNotification.queryNotificationReason == .RecordUpdated { 
      print("queryNotification.recordID \(queryNotification.recordID)") 


     } 
    } 
} 
+0

謝謝。是的,我註冊了遠程通知。 – vomako