iOS未从CloudKit

时间:2017-01-27 20:24:37

标签: ios swift3 cloudkit

我正在尝试为CloudKit记录设置订阅,订阅创建正常,我可以使用CKFetchSubscriptionsOperation成功检索它。但函数 application(_:didReceiveRemoteNotification:)没有被调用...... (我在仪表板中手动更改记录)

订阅以这种方式设置:

let database = CKContainer.default().privateCloudDatabase
let subscription = CKSubscription(recordType: "Device", predicate: NSPredicate(format: "TRUEPREDICATE"), options: .firesOnRecordUpdate)

let notificationInfo = CKNotificationInfo()
notificationInfo.alertLocalizationKey = "DEVICE_UPDATED"
notificationInfo.alertBody = "Device updated in database"

subscription.notificationInfo = notificationInfo

database.save(subscription) { subscription, error in
    if error != nil {
        print(error?.localizedDescription as Any)
    } else {
        print(subscription)
    }
}

通知的注册注册是:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {        
    let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge], categories: nil)
    application.registerUserNotificationSettings(notificationSettings)
    application.registerForRemoteNotifications()

    return true
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    print(userInfo)
}

1 个答案:

答案 0 :(得分:1)

好的,我必须启用推送通知并生成" Apple推送通知服务SSL证书"并将其附加到Apple Developer Provisioning Profiles页面上的应用程序