我想共享一个具有以下结构值的字典: 一些字符串值, videoData:Data, imageData:Base64 。我创建了它,但 UIActivityViewController 无法共享它。
static func exportData(video:Video) -> URL{
let videoData = try! Data(contentsOf: WebRequest.getDataPathwithFile(fileName: video.VideoID))
let image = UIImage(contentsOfFile: WebRequest.getDataPathwithFile(fileName: video.VideoID + ".jpg").path)
let imageData = UIImageJPEGRepresentation(image!, 1)?.base64EncodedString()
let content:[String:Any] = ["title":video.Title,"id":video.VideoID,"duration":video.Duration,"viewcount":video.ViewCount,"data":videoData,"img":imageData]
let saveFileURL = WebRequest.getDataPathwithFile(fileName: video.VideoID + ".bcd")
(content as NSDictionary).write(to: saveFileURL, atomically: true)
return saveFileURL
}
我做得对吗?我想通过Airdrop分享给其他用户,然后他们的iOS设备上的应用程序可以识别它并打开它(我之前写过ImportData函数)
我在 Xcode 8 中使用 Swift3。
最佳答案
对于遇到此问题的任何人,这将适用于更改后的代码:
let imageData = try! Data(contentsOf: WebRequest.getDataPathwithFile(fileName: video.VideoID + ".jpg"))
您应该直接通过以下方式从图像获取数据:
Data(contentsOf:)
关于ios - 通过 UIActivityViewController 共享包含数据的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200672/