func shareVideoToInstagram() {
    let strURL = "http://mobmp4.org/files/data/2480/Tutak%20Tutak%20Tutiya%20Title%20Song%20-%20Remix%20-%20Drunx%20-%20Mp4.mp4"

    let caption = "Some Preloaded Caption"
    let captionStr = caption.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)! as String

    let videoURL = URL(fileURLWithPath: strURL, isDirectory: false)
    let library = ALAssetsLibrary()

    library.writeVideoAtPath(toSavedPhotosAlbum: videoURL) { (newURL, error) in

        if let instagramURL = NSURL(string: "instagram://library?AssetPath=\(videoURL.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)&InstagramCaption=\(captionStr)") {
        print(instagramURL)

        if UIApplication.shared.canOpenURL(instagramURL as URL) {
            UIApplication.shared.openURL(instagramURL as URL)
        }

        } else {
            print("NO")
        }
    }
}

我的instagramURL是这样的:
instagram://library?AssetPath=文件:%2F%2F%2Fhttp://2Fmobmp4.org%2Ffiles%2Fdata%2F2480%2ftuak%252520Tutak%252520Tutiya%252520Title%252520Song%252520-%252520Remix%252520-%252520Drunx%252520-%252520Mp4.mp4&InstagramCaption=Some%20Preloaded%20Caption
我成功地打开了网址,但是我找不到我想在instagram上分享的视频。

最佳答案

func shareVideoToInstagram() {

   let videoFilePath = "http://mobmp4.org/files/data/2480/Tutak%20Tutak%20Tutiya%20Title%20Song%20-%20Remix%20-%20Drunx%20-%20Mp4.mp4"


   let instagramURL = NSURL(string: "instagram://app")

    if (UIApplication.shared.canOpenURL(instagramURL! as URL)) {

      let url = URL(string: ("instagram://library?AssetPath="+videoFilePath))

        if UIApplication.shared.canOpenURL(url!) {
            UIApplication.shared.open(url!, options: [:], completionHandler:nil)
        }

    } else {
        print(" Instagram isn't installed ")
    }

  }

关于ios - 在instagram app iOS上分享videoURL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44015968/

10-08 20:52