ios - 通过 UIActivityViewController 共享包含数据的文件

标签 ios swift swift3 xcode8 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函数)

我在 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/

相关文章:

iphone - iOS Facebook SDK - 检查权限

ios - swift : How to update UILabel from another class X: UIButton

ios - 类型 MyViewController 不符合协议(protocol) 'STPPaymentContextDelegate'

ios - 如何更改 AVPlayer 中播放音频的速度?

swift - 每天激活一个查看周数的功能

swift - 减少以计算 Swift 字典中的元素

ios - 使用 Alamofire 调用 JSONArray

cocoa - deleteCharactersInRange问​​题

ios - 如何正确使用 VarArgs 来本地化字符串?

ios - Swift 3 - Tesseract 识别任何图像处理的抛出错误