2016-06-12 76 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