Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

swift - Not able to tweet video through twitter using UIActivityViewController in iOS

Not able to share the video on twitter through UIActivityViewController.

Text and local video storage works fine. So authentication is not an issue.

If video is stored in the app itself, then the share works fine Path URL

file:///private/var/containers/Bundle/Application/B7855569-3254-4CC2-9573-254D09528E38/podhunt.app/PlugIns/podhunt-shareExtension.appex/demo_video.mp4

If the path is below, then the twitter share does not work Path Url

file:///var/mobile/Containers/Data/PluginKitPlugin/5831780C-50AF-41FA-8435-941CAC47EBE6/Documents/10c41d4a-c161-4c78-bc61-ca789804a982.mp4

This does not work

    URLSession.shared.downloadTask(with: audioUrl) { location, response, error in
    guard let location = location, error == nil else { return }
    do {
           try FileManager.default.moveItem(at: location, to: destinationUrl)
           DispatchQueue.main.async {
               let activityVC = UIActivityViewController(activityItems: [destinationUrl], applicationActivities: nil)
               self.present(activityVC, animated: true, completion: nil)
             }
           } catch {
      }
    }.resume()

This works


URLSession.shared.downloadTask(with: audioUrl) { location, response, error in
    guard let location = location, error == nil else { return }
    do {
           try FileManager.default.moveItem(at: location, to: destinationUrl)
           DispatchQueue.main.async {
           guard let path = Bundle.main.path(forResource: "demo_video", ofType:"mp4") else {
               return
            }
               let activityVC = UIActivityViewController(activityItems: [URL(fileURLWithPath: path)],applicationActivities: nil)
               self.present(activityVC, animated: true, completion: nil)
             }
           } catch {
      }
    }.resume() 

I am working on iOS app extension.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Resolved. Apparently I was sharing mp3 file as an mp4 to twitter which it does not recognize. You cannot share mp3 file to twitter as it does not support audio format.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...