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使用调试器查看,已_UNNotificationCommunicationContext
初始化,但是:
_displayName
为零_recipients
为空(如预期)_contentURL
为零_attachments
是空的sender
被设置为UNNotificationContact
一个\nhandle
&displayName
已正确设置_handleType
似乎设置也正确在应用程序的日志中,我可以看到:
\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 视频遗漏了大量非常重要的细节,但有以下几点:
在您的通知服务扩展中,Info.plist
您需要添加以下内容:
NSExtension
-> NSExtensionAttributes
(dict) -> IntentsSupported
(array) ->INSendMessageIntent
或INStartCallIntent
.
确保您在主应用程序目标上启用了“通信通知”功能。
最后,你的代码看起来是正确的,但你需要添加这个(注意:我只测试了这个INSendMessageIntent
)
// Swift
incomingCommunicationIntent.setImage(image, forParameterNamed: \.sender)
// Objective-C
[incomingCommunicationIntent setImage:image forParameterNamed:"sender"];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5591 次 |
最近记录: |