我有这个问题。我在 AppDelegate 中使用 application:didReceiveRemoteNotification 收到来自 CloudKit 的通知。我能够接收 recordId、获取它并成功保存它。问题是,场景没有刷新。
final class UserData: ObservableObject {
@Published var items: [Item] = []
func saveFetchedItem(recordId: CKRecord.ID, reason: CKQueryNotification.Reason) {
fetchAndSaveRemoteDataFromCloudKit(recordId: recordId, reason: reason, userData: self)
}
}
在应用程序委托中:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let notification: CKNotification = CKNotification(fromRemoteNotificationDictionary: userInfo)!
if notification.notificationType == .query {
let queryNotification = notification as! CKQueryNotification
let recordId = queryNotification.recordID
let reason: CKQueryNotification.Reason = queryNotification.queryNotificationReason
/// reasons:
/// .recordCreated, .recordUpdated, .recordDeleted
UserData().saveFetchedItem(recordId: recordId!, reason: reason)
}
completionHandler(.newData)
}
在 fetchAndSaveRemoteDataFromCloudKit 中,我传递 UserData 以保存收到的项目并且它可以工作。问题是,我在列表上显示项目,但列表不会刷新,即使我打印 userData.items 并且新项目就在那里。
AppDelegate 和 SceneDelegate 之间是否存在连接以刷新场景/窗口?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)