推送通知 – 如何设置最小的CKSubscription?

前端之家收集整理的这篇文章主要介绍了推送通知 – 如何设置最小的CKSubscription?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想设置一个简单的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
}
原文链接:https://www.f2er.com/iOS/330077.html

猜你在找的iOS相关文章