【问题标题】:Download video from URL and share it on Facebook, Messages, Twitter using UIActivityViewController使用 UIActivityViewController 从 URL 下载视频并在 Facebook、Messages、Twitter 上分享
【发布时间】:2018-04-05 18:06:41
【问题描述】:

我正在使用Alamofire 进行联网并使用Swift 4

我需要从 URL 下载视频并将其存储在特定位置,然后在 FacebookMessagesTwitter 等上使用 UIActivityViewController 共享它。

有人可以提供一些示例代码或指导我吗?

问候!!

【问题讨论】:

    标签: ios swift sharing uiactivityviewcontroller


    【解决方案1】:

    尝试使用 Alamofire 下载视频

    func downloadVideo() {
        let destination = DownloadRequest.suggestedDownloadDestination()
        let url = "https://lynda_files2-a.akamaihd.net/secure/courses/391599/VBR_MP4h264_main_SD/391599_00_01_WX30_welcome.mp4?c3.ri=3770828196132302975&hashval=1522966719_0c357049da0562665ab3f99ccd3e8bca"
    
        Alamofire.download(url, to: destination).downloadProgress(queue: DispatchQueue.global(qos: .utility)) { (progress) in
            print("Progress: \(progress.fractionCompleted)")
        } .validate().responseData { [weak self] (response)  in
            self?.shareVideo(from: response.destinationURL!)
        }
    }
    

    并使用 UIActivityViewController 分享

    func shareVideo(from url: URL) {
        let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
        present(activityViewController, animated: true, completion: nil)
    }
    

    【讨论】:

    • 谢谢Jaba,明天我会检查并告诉你
    • 谢谢,效果很好。只是另一件事它在哪里下载。我需要手动清除它吗?
    • 您可以使用缓存目录来保存临时数据。系统将在必要时删除。像这样更改目标 let destination = DownloadRequest.suggestedDownloadDestination(for: .cachesDirectory, in: .userDomainMask)
    • 解决了我的问题。还添加了一种在应用启动时清除缓存的方法。谢谢队友:)
    猜你喜欢
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 2015-03-18
    相关资源
    最近更新 更多