我一直在尝试将我的(本地和推送)通知更新为通信通知。
当用户收到来自其朋友之一的通信事件时,我希望显示的通知包含该朋友的个人资料图片。就像新的 iMessage 应用程序一样。
观看专门的 WWDC2021 会议后,我向我的 SwiftUI 应用程序添加了 Siri Intent:
// I correctly added the StartCallIntent to both my app's Info.plist and the Siri Intent extension.
<array>
<string>INStartCallIntent</string>
</array>
并尝试使用以下内容更新我的通知流程:
let image = INImage(imageData: friend.profilePicture.cellImage.pngData()!)
let intentFriend = INPerson(
personHandle: INPersonHandle(value: friend.phoneNumber, type: .phoneNumber),
nameComponents: friend.nameComponents,
displayName: friend.localName,
image: image,
contactIdentifier: nil,
customIdentifier: nil,
isMe: false,
suggestionType: .instantMessageAddress
)
let incomingCommunicationIntent = INStartCallIntent(
callRecordFilter: nil,
callRecordToCallBack: nil,
audioRoute: .unknown,
destinationType: .normal,
contacts: [intentFriend],
callCapability: .audioCall
)
let interaction = INInteraction(intent: incomingCommunicationIntent, response: nil)
interaction.direction = .incoming
interaction.donate(completion: nil)
do {
let result = try notification.updating(from: incomingCommunicationIntent)
return result
} catch let error {
print("-- \(error)")
// TODO: Handle error here
}
return notification
返回的UNNotificationContent
然后处理为显示为推送通知或本地通知。
虽然上面的代码没有崩溃并且看起来/工作/,但通知看起来没有任何不同。
使用调试器查看,_UNNotificationCommunicationContext
已初始化,但是:
-
_displayName
is nil
-
_recipients
为空(如预期)
-
_contentURL
is nil
-
_attachments
是空的
-
sender
is set to a UNNotificationContact
on which
-
handle
& displayName
已正确设置
-
_handleType
似乎设置也正确
在应用程序的日志中,我可以看到:
[Intents] -[INCache cacheableObjectForIdentifier:] Unable to find cacheable object with identifier EDB29166-E46A-CF23-AB27-8B61F763A039 in cache.
[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.
为了正确显示朋友的个人资料图片,我缺少什么?
谢谢