提问人:Ilya Krigouzov 提问时间:7/16/2023 更新时间:7/16/2023 访问量:24
无法从 Siri 获取音频消息 INSendMessageIntent
Can't get audio message from Siri INSendMessageIntent
问:
卡在尝试使用 SiriKit 发送语音消息时。
调用 Siri 命令,它正在录制消息,然后调用Send audio message with AppName
func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void)
但是附加的长度为 0,当我尝试通过直接 URL 获取文件时,我收到了消息Data
file:///var/tmp/SiriMessages/E262A828-A24E-452E-BF70-867F5653BEFE.caf: Unable to open «E262A828-A24E-452E-BF70-867F5653BEFE.caf», you have no permissions.
我没有找到任何权限设置,所以寻求帮助。
func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let MIMEType = "audio/x-caf"
var resultCode: INSendMessageIntentResponseCode = .failure
var response = INSendMessageIntentResponse(code: resultCode, userActivity: userActivity)
if let audio = intent.attachments!.first?.audioMessageFile {
let networkService = NetworkService() // Test service for uploading files
let audioData = audio.data
let filePath = audio.fileURL!
Task {
var resultCode: INSendMessageIntentResponseCode = .success
var response = INSendMessageIntentResponse(code: resultCode, userActivity: userActivity)
await networkService.uploadAudioMessage(filePath: filePath, withMIMEType: MIMEType) // Here I've got permission error
print("Size of file: \(audioData.count)") // Will output Size of file: 0
print("Result success")
completion(response)
return
}
} else {
print("no voice message attached")
completion(response)
return
}
}
答: 暂无答案
评论