ios - 在 iOS 版 Instagram 应用程序上分享视频网址

标签 ios swift instagram sharing

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=file:%2F%2F%2Fhttp:%2Fmobmp4.org%2Ffiles%2Fdata%2F2480%2FTutak%252520Tutak%252520Tutiya%252520Title%252520Song%252520-%252520Remix%252520-%252520Drunx%252520-%252520Mp4.mp4&InstagramCaption=Some%20Preloaded%20Caption

我成功打开了 URL,但找不到我想在 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 - 在 iOS 版 Instagram 应用程序上分享视频网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44015968/

相关文章:

swift - 试图清除文档文件夹 Swift

php - 如何使用 API 显示 Instagram 个人资料图片

javascript - Onsen - 动态添加 ons-carousel-items

android - PhoneGap 3.3.0 又名 Cordova 与 PhoneGap 3.2.0

ios - 仅当隐藏文本字段时才使用键盘移动 View

ios - React Native 和 Redux : How to create unique route key for navigation?

ios - 如何从 NSObject 类显示 UIViewController?

ios - 当 UITableViewCell 中的行数固定时,UILabel 占用空间吗?

ios - 将 3D SceneKit 节点位置映射到 2D 坐标 - projectPoint 不起作用

php - 如何通过 API 使用 PHP 获取 Instagram 照片?