gpt4 book ai didi

ios - CKQuery订阅 : Failing to Make Subscription

转载 作者:行者123 更新时间:2023-11-28 14:16:02 27 4
gpt4 key购买 nike

我有一个正在使用 CloudKit 开发的 iOS 应用程序。我正在尝试订阅。

import CloudKit

class HomeViewController: UIViewController {
override func viewDidLoad() {
registerSubscription()
}

func registerSubscription() {
let cloudContainer = CKContainer(identifier: "iCloud.com.xxx.XXXXX")
let privateDB = cloudContainer.privateCloudDatabase
let predicate = NSPredicate(format: "TRUEPREDICATE") // TRUEPREDICATE: all records of the specified type match the predicate
let subscription = CKQuerySubscription(recordType: "PrivateRecords", predicate: predicate, options: .firesOnRecordCreation)
privateDB.save(subscription, completionHandler: ({returnRecord, error in
if let err = error {
print("Subscription has failed: \(err.localizedDescription)")
} else {
print("Subscription set up successfully")
print("Subscription ID: \(subscription.subscriptionID)")
}
}))
}
}

而且它会一直出错。错误说明如下。

Subscription with a nil notificationInfo: CKQuerySubscription: 0x7fd7bfca7ec0; ; Query Subscription: recordType=PrivateRecords, predicate=TRUEPREDICATE, subscriptionOptions=1, subscriptionID=728863F8-3852-4A12-B5C6-F65EC945207A, zoneID=(null)

我可以根据订阅 ID 删除订阅。但是每次我运行这个应用程序时它都会给我一个不同的 ID。实际上,我已经对 ma​​cOS 应用程序做了同样的事情。它有一个订阅。此外,我大约一周前删除了一个订阅类型,看看会发生什么。我真的不知道订阅 ID 有什么用。

那么我在订阅时做错了什么?谢谢。

enter image description here

最佳答案

CKQuerySubscriptions 有一个属性 notificationInfo,你需要做的是像下面这样的事情:

let notification = CKSubscription.NotificationInfo()
notification.alertBody = "You have a new message"
notification.shouldSendContentAvailable = true

newSubscription.notificationInfo = notification

关于ios - CKQuery订阅 : Failing to Make Subscription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52177054/

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