iOS 15 通讯通知图片未显示

Ant*_*ché 11 apple-push-notifications wwdc uilocalnotification swift ios15

我一直在尝试将我的(本地和推送)通知更新为通信通知。

\n

当用户收到来自其朋友之一的通信事件时,我希望显示的通知包含该朋友的个人资料图片。就像新的 iMessage 应用程序一样。

\n

观看专门的 WWDC2021 会议后,我向我的 SwiftUI 应用程序添加了 Siri Intent:

\n
// I correctly added the StartCallIntent to both my app\'s Info.plist and the Siri Intent extension.\n<array>\n    <string>INStartCallIntent</string>\n</array>\n
Run Code Online (Sandbox Code Playgroud)\n

并尝试使用以下内容更新我的通知流程:

\n
// I correctly added the StartCallIntent to both my app\'s Info.plist and the Siri Intent extension.\n<array>\n    <string>INStartCallIntent</string>\n</array>\n
Run Code Online (Sandbox Code Playgroud)\n

然后,返回的信息UNNotificationContent将被处理为显示为推送通知或本地通知。

\n

虽然上面的代码不会崩溃并且似乎/工作/,但通知看起来没有任何不同。\n使用调试器查看,已_UNNotificationCommunicationContext初始化,但是:

\n
    \n
  • _displayName为零
  • \n
  • _recipients为空(如预期)
  • \n
  • _contentURL为零
  • \n
  • _attachments是空的
  • \n
  • sender被设置为UNNotificationContact一个\n
      \n
    • handle&displayName已正确设置
    • \n
    • _handleType似乎设置也正确
    • \n
    \n
  • \n
\n

在应用程序的日志中,我可以看到:

\n
[Intents] -[INCache cacheableObjectForIdentifier:] Unable to find cacheable object with identifier EDB29166-E46A-CF23-AB27-8B61F763A039 in cache.\n[Intents] -[INCache cacheableObjectForIdentifier:] Unable to find cacheable object with identifier intents-remote-image-proxy:?proxyIdentifier=EDB29166-E46A-CF23-AB27-8B61F763A039.png&storageServiceIdentifier=com.apple.Intents.INImageServiceConnection in cache.\n
Run Code Online (Sandbox Code Playgroud)\n

为了正确显示朋友的个人资料图片,我缺少什么?

\n

谢谢

\n

小智 13

不幸的是,苹果在记录通信通知方面做得并不好,他们的 WWDC 视频遗漏了大量非常重要的细节,但有以下几点:

  1. 在您的通知服务扩展中,Info.plist您需要添加以下内容: NSExtension-> NSExtensionAttributes(dict) -> IntentsSupported(array) ->INSendMessageIntentINStartCallIntent.

  2. 确保您在主应用程序目标上启用了“通信通知”功能。

  3. 最后,你的代码看起来是正确的,但你需要添加这个(注意:我只测试了这个INSendMessageIntent

// Swift
incomingCommunicationIntent.setImage(image, forParameterNamed: \.sender)

// Objective-C
[incomingCommunicationIntent setImage:image forParameterNamed:"sender"];
Run Code Online (Sandbox Code Playgroud)