【问题标题】:Cannot share video with UIActivityViewController in IOS 14无法在 IOS 14 中与 UIActivityViewController 共享视频
【发布时间】:2021-06-15 10:24:15
【问题描述】:

在 IOS > 14 中与 UIActivityViewController 共享视频时出现错误,但 14 岁以下的 iOS 工作正常。不知道为什么?

2021-03-15 23:55:20.866820+0700 AnyBackup[3249:1433997] 无法创建沙盒扩展。错误:错误域=NSPOSIXErrorDomain 代码=1“不允许操作”UserInfo={NSLocalizedDescription=无法为 URL /var/mobile/Media/DCIM/100APPLE/IMG_0415 创建类型为 com.apple.app-sandbox.read 的沙盒扩展。移动。错误:不允许操作}

2021-03-15 23:55:20.867564+0700 AnyBackup[3249:1457502] [默认] 无法为 URL 发出沙盒令牌:'file:///var/mobile/Media/DCIM/100APPLE/IMG_0415。 MOV' 错误:'Error Domain=NSPOSIXErrorDomain Code=1 "Operation not allowed" UserInfo={NSLocalizedDescription=Cannot issue a sandbox extension for file "/var/mobile/Media/DCIM/100APPLE/IMG_0415.MOV": Operation not allowed }'

我需要帮助????

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    首先确保您的视频在您的DocumentDirectory 中可用,然后您可以通过URL of Directory 分享它,如下所示。

    通过 URL 分享视频:

    let url = self.documentDirectory().appendingPathComponent("yourFilename")
    let share = UIActivityViewController(activityItems: [url], applicationActivities: nil)
    share.popoverPresentationController?.sourceView = self.view
    self.present(share, animated: true, completion: nil)
    

    获取 DocumentDirectory 的 URL:

    func documentDirectory() -> URL {
      let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
      return documentsDirectory
    }
    

    【讨论】:

    • 问题已解决,感谢您的建议。
    • 不客气。如果我的回答有用,你可以点赞。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多