首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >未收到CloudKit推送通知

未收到CloudKit推送通知
EN

Stack Overflow用户
提问于 2014-06-17 01:12:58
回答 1查看 4K关注 0票数 18

我正在写一个使用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);
}

但是,它从未被调用过。

EN

回答 1

Stack Overflow用户

发布于 2014-07-09 17:05:38

我现在收到从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属性,可以在后台接收通知-这似乎也可以工作(从Beta4开始)。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24248822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档