【问题标题】:CKQueryNotification not received on MacCatalyst buildMacCatalyst 构建未收到 CKQueryNotification
【发布时间】:2020-08-15 00:52:45
【问题描述】:

我的应用程序通常在 iOS 或 iPadOS 上从 CKQuerySubscription 接收 CKQueryNotification,但使用具有相同捆绑 ID(从 Xcode 11.6 生成)的 MacCatalyst,即使如此,它也永远不会收到 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 上立即触发。

任何想法为什么? Apple 论坛上有一个帖子,但还没有看到解决方案:https://developer.apple.com/forums/thread/125069

【问题讨论】:

    标签: swift xcode cloudkit mac-catalyst


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您没有共享足够的代码让我们帮助您,所以我来猜测一下。尝试如下定义您的 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
      

      【讨论】:

      • 对不起,我已经这样做了,db.fetchAllSubscriptions 会正确返回订阅
      猜你喜欢
      • 2021-02-04
      • 2020-12-10
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多