【问题标题】:Not receiving CloudKit push notifications未收到 CloudKit 推送通知
【发布时间】:2014-08-06 13:56:40
【问题描述】:

我正在编写一个使用 CloudKit 的小应用程序。由于某种原因,当有与查询匹配的新记录时,应用程序不会收到任何通知。有没有人能够使用此功能?

我在应用程序以及 CloudKit 仪表板中创建新记录。记录非常简单,只有一个整数字段。

创建记录:

 CKRecord *record = [[CKRecord alloc] initWithRecordType:kSISCloudKitRecordTypeTest];
 record[@"value"] = @1;
 [self.publicDatabase saveRecord:record completionHandler:^(CKRecord *record, NSError *error)
  {
       // this call succeeds, no error.
  }];

注册通知:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [application registerForRemoteNotifications];
}

创建订阅:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"value = 1"];

CKSubscription *subscription = [[CKSubscription alloc]
                                initWithRecordType:kSISCloudKitRecordTypeTest
                                predicate:predicate
                                options:CKSubscriptionOptionsFiresOnRecordCreation];

CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.alertLocalizationKey = @"LOCAL_NOTIFICATION_KEY";
notificationInfo.soundName = @"Party.aiff";
notificationInfo.shouldBadge = YES;
subscription.notificationInfo = notificationInfo;

[self.publicDatabase saveSubscription:subscription
                    completionHandler:^(CKSubscription *subscription, NSError *error)
 {
     // this succeeds as well, at least the 1st time I run it.
     // on subsequent calls it returns an error "duplicate subscription", which is OK by me.
 }

运行上述代码并在仪表板中创建新记录后,我希望调用此应用委托方法:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    CKNotification *cloudKitNotification = [CKNotification notificationFromRemoteNotificationDictionary:userInfo];
    NSLog(@"cloudKitNotification: %@", cloudKitNotification);
}

但是,它永远不会被调用。

【问题讨论】:

  • 您尝试了application:didReceiveRemoteNotification: fetchCompletionHandler: 委托方法吗?
  • @zoul,那个也没有被调用。

标签: ios ios8 cloudkit cksubscription


【解决方案1】:

我现在收到自 Beta 3 以来的通知:

{
    aps =     {
    };
    ck =     {
        ce = 2;
        cid = "iCloud.com.domain.App";
        nid = "0b3ae470-d2c0-4f35-a817-12a899ee5964";
        qry =         {
            dbs = 2;
            fo = 1;
            rid = 88aee11ca88d4ecc45bf57c898b360c8e7e3d8bb;
            zid = "_defaultZone";
            zoid = "_defaultOwner";
        };
    };
}

此外,CKNotificationInfo 上有一个 shouldSendContentAvailable 属性,可以在后台接收通知 - 现在似乎也可以工作(从 Beta 4 开始)。

【讨论】:

  • 谢谢!很高兴知道它现在已修复。
  • 好像苹果改变了通知注册api。即使我的应用程序在后台使用一行+ [UIApplication registerForRemoteNotifications];,我是否应该接收推送通知,还是我需要更多?
  • 通知 API 有点麻烦,但我认为就是这样,还有 Info.plist 文件中的 remote-notification 键。
  • 我也在使用 Beta 3 并且订阅对我不起作用,即我没有收到任何远程通知。 Zoul,这仍然对你有用吗?你能发布适合你的代码吗?
  • 我仍然无法在 Beta 5 中使用它。有人成功了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
  • 2019-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多