MacCatalyst版本上未收到CKQueryNotification

问题描述

我的应用通常在iOS或iPadOS上从CKQueryNotification接收CKQuerySubscription,但是对于MacCatalyst具有相同的捆绑包ID(从Xcode 11.6生成),它甚至从不接收CKQueryNotification >

func application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)

在应用启动时会正确调用-每当CloudKit上的记录发生更改时,方法

func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Swift.Void)

从不触发MacCatalyst版本,而立即在iOS上触发。

任何想法为何?苹果论坛上有一个话题,但是还没有解决的方法:https://developer.apple.com/forums/thread/125069

解决方法

对于在开发应用程序时也遇到此问题的任何人,我决定以任何方式发布该应用程序,并发现在App Store版本中,催化剂应用程序实际上几乎可以立即收到通知。因此,这似乎是CloudKit的调试环境错误。

,

您共享的代码不足,无法为我们提供帮助,因此,我猜测一下。尝试如下定义您的notificationInfo值,看看是否有区别。在didRegisterForRemoteNotifications内部:

    // This is your subscription object
    let subscription = CKQuerySubscription(recordType: "Subscription",predicate: NSPredicate(format: "TRUEPREDICATE"),options: [.firesOnRecordCreation,.firesOnRecordUpdate])
    
    // Here we customize the notification message
    let info = CKSubscription.NotificationInfo()

    info.shouldSendContentAvailable = true
    info.desiredKeys = ["identifier","title","date"]
    info.soundName = ""
    info.alertBody = ""
    info.title = ""
    info.alertActionLocalizationKey = ""

    // Assign the notification info to your subscription
    subscription.notificationInfo = info

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...