8

是否可以在Instagram上分享視頻而不保存到用戶的相機膠捲?在iOS上分享視頻到Instagram

這是我試過到目前爲止:

 let instagramURL = URL(string: "instagram://app")! 
     if (UIApplication.shared.canOpenURL(instagramURL)) { 

      self.documentController = UIDocumentInteractionController(url: videoURL) 
      self.documentController.delegate = self 
      self.documentController.uti = "com.instagram.exlusivegram" 
      self.documentController.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true) 

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

videoURL是視頻的網址我保存在文檔文件夾。
如果我instagram.igo保存的URL結尾,然後當我選擇的Instagram分享這樣開:
enter image description here

如果我保存的.mov影片結尾,它似乎Instagram的分享與開放照片(如視頻縮略圖)而不是視頻。

+0

videoURL是你的本地路徑url? –

+0

@HimanshuMoradiya是其I保存到文件視頻文件夾 – Eyal

+0

商店,視頻在相機膠捲不是文檔文件夾我看到你的問題,你寫你存儲視頻文件的文件夾沒有相機膠捲,所以你需要存儲的視頻在相機膠捲所以其顯示在instagram –

回答

4

究竟做過什麼,錯的是難以確定的,但我會盡力解決,你可能錯了。

首先確保該videoURL在本地定義。當我寫一個應用程序發佈到Instagram的,我先用文件管理器中定義的路徑,如:

let tempDirectory = FileManager().temporaryDirectory 
var postingPath = tempDirectory.appendingPathComponent("postingVideo") 
postingPath = postingPath.appendingPathExtension("igo") 

我然後寫電影進入這個目錄,幾乎有相同的代碼爲你。 請考慮到您需要創建igo文件夾,然後將影片保存到此文件夾中。如果您嘗試引用您擁有影片的文件夾,則您的應用程序將不會讀取影片文件,也不會發布任何內容。當它是來自照片庫的電影文件時,請使用AVExportSession並將其導出到postsPath。

self.instagramController = UIDocumentInteractionController.init(url: postingPath) 
self.instagramController.uti = "com.instagram.exclusivegram" 
self.instagramController.delegate = self 
self.instagramController.presentOpenInMenu(from: 
self.navigationItem.rightBarButtonItem!, animated: true) 

但是,你需要讓你的類張貼到Instagram的堅持UIDocumentInteractionControllerDelegate,否則你需要投的自我。您還需要包含Social。我不認爲你在這篇文章的第二部分做了任何錯誤,因爲你會得到xcode錯誤和警告。

我希望第一部分可以幫助你進一步,因爲我不認爲第二部分給你的問題。

+0

「你需要創建igo文件夾,然後將電影保存到這個文件夾」文件夾?它只是需要igo不是的文件擴展名? – Eyal

+0

是否爲你工作?你成功上傳視頻(不是照片!)到Instagram?而不是從你的相機膠捲的視頻.. – Eyal

+0

我只是試圖讓一個應用程序與instagram工作,併發佈一個網站的視頻,而不是照片庫似乎不工作。我只能建議您將您的應用程序與照片庫集成。 – MacUserT