我想设置一个简单CKSubscription
的通知我recordType
创建了一个,如何?
问问题
2158 次
2 回答
13
经过一段时间的试验,这是设置最小 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
}
于 2014-07-23T16:21:56.477 回答
3
你注册通知了吗?您的应用程序中应该有类似的内容 didFinishLaunchingWithOptions:
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
application.registerForRemoteNotifications()
我创建了一个工作演示,可在https://github.com/evermeer/EVCloudKitDao获得
于 2014-07-23T10:00:20.973 回答