简体   繁体   English

CloudKit:查询订阅请求

[英]CloudKit: query subscriptions request

I'm working in app using CloudKit and I'm creating a subscription to CloudKit. 我正在使用CloudKit在应用程序中工作,并且正在创建CloudKit的订阅。 here is my code: 这是我的代码:

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);
                   }

               }];

My question to you guys. 我对你们的问题。 How can I query or validate the user subscription to CloudKit ? 如何查询或验证用户对CloudKit的订阅?

A subscription is nothing more than a CKPredicate that is active on the server side instead of in your app. 订阅只不过是在服务器端而不是您的应用程序中处于活动状态的CKPredicate。 If you want to validate if the predicate is correct, then just execute it as a query and see what you get back. 如果您想验证谓词是否正确,则只需将其作为查询执行即可,然后您将得到什么。

Make sure your application difFinishLaunchingWithOptions has the following lines of code: 确保您的应用程序difFinishLaunchingWithOptions具有以下代码行:

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

Also make sure you handle incoming notifications by adding this: 还请确保您通过添加以下内容来处理传入的通知:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM