如何使用Swift 3在应用程序中共享音频文件? [英] How do I share an Audio File in an App using Swift 3?

查看:172
本文介绍了如何使用Swift 3在应用程序中共享音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何与其他应用程序共享应用程序文档目录中存在的音频文件?

How do I share an audio file which exists in my apps document directory to other apps?

要详细说明这个问题,我的意思是,当用户在应用程序中点击共享按钮时,他们应该能够通过电子邮件将录制的音轨发送给其他人,或者能够将其发送到一系列其他应用,这些应用可以处理诸如soundcloud之类的音频.

To elaborate on this question, what I mean is when a user taps a share button in the app they should be able to email their recorded audio track to another person, or alternatively to be able to send it across to a range of other apps which can handle audio like perhaps soundcloud.

研究该主题,我发现:

  • UIActivityViewController
  • UIDocumentInteractionController
  • UIActivityViewController
  • UIDocumentInteractionController

由于我的应用程序对一个人的声音进行了录音,因此他们应该可以共享,并且尽管通过堆栈溢出进行了搜索,但我仍然无法找到一个代码示例来说明如何在Swift中实现此选项应用程序.我可以要求有关如何实现的建议和示例代码.非常感谢,

Since my application makes an audio recording of a person's voice which they should be able to share, and despite searching through stack overflow, I have not been able to find a code example of how exactly this option can be implemented in a Swift app. Can I request suggestions and example code on how this may be accomplished. Many Thanks,

推荐答案

Swift 3.x:

        let activityItem = URL.init(fileURLWithPath: Bundle.main.path(forResource: "fileName", ofType: "mp3")!)

        let activityVC = UIActivityViewController(activityItems: [activityItem],applicationActivities: nil)
        activityVC.popoverPresentationController?.sourceView = self.view

        self.present(activityVC, animated: true, completion: nil)

这篇关于如何使用Swift 3在应用程序中共享音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆