通过 UIActivityViewController 共享包含数据的文件
Sharing a file with data in it by UIActivityViewController
我想分享一个具有以下结构值的字典:
一些字符串值,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 func)
我在 Xcode 8.
中使用 Swift3
对于遇到此问题的任何人,这将适用于更改后的代码:
let imageData = try! Data(contentsOf: WebRequest.getDataPathwithFile(fileName: video.VideoID + ".jpg"))
您应该直接通过以下方式从图像中获取数据:
Data(contentsOf:)
我想分享一个具有以下结构值的字典: 一些字符串值,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 func)
我在 Xcode 8.
中使用 Swift3对于遇到此问题的任何人,这将适用于更改后的代码:
let imageData = try! Data(contentsOf: WebRequest.getDataPathwithFile(fileName: video.VideoID + ".jpg"))
您应该直接通过以下方式从图像中获取数据:
Data(contentsOf:)