- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 iOS 的共享表功能共享音频文件。我无法将音频文件音频文件放入共享表中进行共享。目前,电子邮件中没有添加附件或音频文件(例如)。
我有以下检索音频文件的代码。我可以使用 MFMailComposeViewController
将其作为电子邮件明确发送,但我更愿意将其“扔”到共享表中,以允许用户将文件上传到电子邮件/保管箱/谷歌驱动器。
这可能吗?
let objectsToShare: NSMutableArray = []
let docsDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let soundFilePath = (docsDir as NSString).stringByAppendingPathComponent(fileName)
let fileManager = NSFileManager.defaultManager()
let fileContent = fileManager.contentsAtPath(soundFilePath)
objectsToShare.addObject(fileContent!)
if let objects = objectsToShare as [AnyObject]? {
let activityVC = UIActivityViewController(activityItems: objects, applicationActivities: nil)
if let subject = noteTitle.text as String? {
activityVC.setValue(subject, forKey: "subject")
}
self.presentViewController(activityVC, animated: true, completion: nil)
}
提前致谢:)
最佳答案
您将文件内容 放入objectsToShare
。 activityVC
可以共享内容,但不知道它是要共享的文件。
我想你需要一个 UIDocumentInteractionController
反而。就像这个未经测试的代码:
var dic:UIDocumentInteractionController? // has to be instance variable not buried in a method, or the dic is deallocated before it can open the file.
func shareFile(filePath:String, fileName: String, from:UIBarButtonItem) {
let url = NSURL(fileURLWithPath: filePath)
dic = UIDocumentInteractionController(URL:url)
dic?.UTI = fileName
dic?.presentOptionsMenuFromBarButtonItem(from, animated: true)
}
如果您在 shareFile
方法中将 dic
设置为局部变量,它往往会在文件打开之前被释放,这会让您成为 Couldn' t get file size for (null)
错误。改为将其作为类的实例变量。
关于ios - 通过 sharesheet 共享音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35155725/
我正在尝试使用 iOS 的共享表功能共享音频文件。我无法将音频文件音频文件放入共享表中进行共享。目前,电子邮件中没有添加附件或音频文件(例如)。 我有以下检索音频文件的代码。我可以使用 MFMailC
我正在寻找 Facebook 和 Twitter 设计按钮。我看到一些应用程序具有漂亮的按钮设计(原始 CI)。这些按钮在任何地方都可用吗?它们应该看起来像 Facebook 和 Twitter 的默
我想使用共享表共享一个文件,并编写了似乎工作正常的代码。但是我一直在日志中看到这些错误消息(使用 Xcode 11.3) [ShareSheet] connection invalidated 我有两
我是一名优秀的程序员,十分优秀!