gpt4 book ai didi

push-notification - 如何设置最小的CKSubscription?

转载 作者:行者123 更新时间:2023-12-04 07:26:29 27 4
gpt4 key购买 nike

我想设置一个简单的CKSubscription,通知我创建了recordType,怎么办?

最佳答案

经过一段时间的尝试后,这就是如何设置最小的CKSubscription的方法。您必须在设备上进行测试,推送通知在模拟器上不起作用。您可以在Dashboard中添加记录,这也会触发推送通知。

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
}

关于push-notification - 如何设置最小的CKSubscription?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24905390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com