我想设置一个简单的CKSubscription,通知我创建了一个recordType,怎么样?
解决方法
经过一段时间的实验,这是如何设置一个最小的CKSubscription.您必须在设备上测试,推送通知在模拟器上不起作用.您可以在仪表板中添加记录,这也将触发推送通知.
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert,categories: nil)) application.registerForRemoteNotifications() return true } func someFunc() { // <- you need to call once in app life time,and again when it was removed / installed let defaultContainer = CKContainer.defaultContainer() let publicDatabase = defaultContainer.publicCloudDatabase let subs = CKSubscription(recordType: "xxx",predicate: NSPredicate(value: true),subscriptionID: "yyy",options: .FiresOnRecordCreation) subs.notificationInfo = CKNotificationInfo() subs.notificationInfo.alertBody = "New item added" publicDatabase.saveSubscription(subs,completionHandler: {subscription,error in}) } func application(application: UIApplication!,didReceiveRemoteNotification userInfo: [NSObject : AnyObject]!) { // <- this method will invoked }