CloudKit:查询订阅请求

时间:2015-06-04 07:12:08

标签: ios objective-c cloudkit cksubscription

我正在使用CloudKit在app中工作,而且我正在创建对CloudKit的订阅。这是我的代码:

CKSubscription *subscription = [[CKSubscription alloc]
                                initWithRecordType:recordType
                                predicate:predicate
                                options:CKSubscriptionOptionsFiresOnRecordCreation |
                                CKSubscriptionOptionsFiresOnRecordUpdate |
                                CKSubscriptionOptionsFiresOnRecordDeletion];


CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.shouldSendContentAvailable = YES;
subscription.notificationInfo = notificationInfo;
notificationInfo.shouldBadge = YES;
CKDatabase *publicDatabase = [container publicCloudDatabase];
[publicDatabase saveSubscription:subscription
               completionHandler:^(CKSubscription *subscription, NSError *error) {
                   if (!error)
                   {
                       NSLog(@"subscription success!");
                   }
                   else
                   {
                       NSLog(@"subscription  error%@", error.localizedDescription);
                   }

               }];

我向你们提问。如何查询或验证CloudKit的用户订阅?

1 个答案:

答案 0 :(得分:0)

订阅只不过是在服务器端而不是在应用程序中活动的CKPredicate。如果要验证谓词是否正确,那么只需将其作为查询执行,看看你得到了什么。

确保您的应用程序difFinishLaunchingWithOptions具有以下代码行:

    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
    application.registerForRemoteNotifications()

还要确保通过添加以下内容来处理传入通知:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    NSLog("Push received.. Should be handled..")
}