0

我正在使用 CloudKit 在应用程序中工作,并且正在创建对 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 的订阅?

4

1 回答 1

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..")
}
于 2015-06-04T08:46:10.900 回答