Share video to Instagram on iOS
Asked Answered
S

1

8

Is it possible to share a video on Instagram without saving it to the user's Camera Roll?

this is what i tried so far:

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 is the URL of the video i saves in the Documents folder.
if I save the URL with Instagram.igo at the end, then when i choose Instagram to share it opens like this:
enter image description here

if I save the video with .mov at the end, it seems that Instagram share opens with a photo (like video thumbnail) and not a video.

Shumaker answered 15/6, 2017 at 11:31 Comment(6)
videoURL is your local path url ?Chromatid
@HimanshuMoradiya yes its the video i saved to the Documents folderShumaker
store that video in camera roll not document folder i see your question you write that you store video in document folder not camera roll so you need to store video in camera roll so its display in instagramChromatid
@HimanshuMoradiya yeah i also wrote i don't want to save it to camera roll. saving to camera roll will require to ask user permissions to access his photos library. and I dont want that.Shumaker
i think you have to read instagram.com/developer/reviewChromatid
@HimanshuMoradiya yes i read that, but it doesnt say anything about uploading a video on ios. there is an explanation about uploading a photo, but this is not the case, and applying the same thing to a video upload doesnt work.Shumaker
S
6

What exactly you did wrong is difficult to determine, but I'll try to address where you might have been wrong.

First of all make sure that the videoURL is defined locally. When I wrote an app posting to Instagram, I first defined the path with file manager, like:

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

I then wrote the movie into this directory and almost have the same code as you. Do take into consideration that you need to create the igo folder and then save the movie into this folder. If you try to refer to the folder you have the movie in, your app will not read the movie file and nothing will be posted. When it is a movie file from the photo library, use an AVExportSession and export it to the postingPath.

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)

However, you do need to make your class posting to instagram adhere to the UIDocumentInteractionControllerDelegate, otherwise you need cast self. You also need to include Social. I don't think you have done anything wrong in the second part of this post, because you would have gotten xcode errors and warnings.

I hope the first part can help you further, since I don't think the second part has given you problems.

Speciality answered 18/6, 2017 at 10:53 Comment(3)
"you need to create the igo folder and then save the movie into this folder" folder? its just the file extension that needs to be igo no?Shumaker
did that work for you? did you succeed uploading a video (not photo!) to instagram? and not a video from your camera roll..Shumaker
I just tried to make an app working with instagram and posting a video from a url other than the photo library appears not to work. I can only advice you to integrate your app with the photo library.Speciality

© 2022 - 2024 — McMap. All rights reserved.