Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share video to Instagram feed from iOS

I've been trying to create a sharing experience for our app where Instagram launches giving these two options:

enter image description here

Facebook has a pretty lean documentation about it. I tried all the possible permutations using the UIDocumentInteractionController. I tried using as uti com.instagram.photo and com.instagram.video with the ig extension but I keep getting the standard sharing popover instead of launching Instagram directly. Tried also com.instagram.exclusivegram with igo but that seems to be supposed to trigger the standard popover anyway.

Latest code:

func shareVideo(_ filePath: String) {
  let url = URL(fileURLWithPath: filePath)
  if(hasInstagram()){
    let newURL = url.deletingPathExtension().appendingPathExtension("ig")
    do {
      try FileManager.default.moveItem(at: url, to: newURL)
    } catch { print(error) }

    let dic = UIDocumentInteractionController(url: newURL)
    dic.uti = "com.instagram.photo"
    dic.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true)
  }
}
like image 359
Nuthinking Avatar asked Oct 30 '18 07:10

Nuthinking


People also ask

How do you share a video on Instagram Feed?

Tap below the photo or video in Feed. Tap Add post/video/reel to your story. Tap in the bottom right. Tap Share.

How do you post a video on Instagram without reels?

With today's update, users will still be able to upload their non-Reels videos in the same way as before — by clicking on the plus sign (+) in the top-right corner of the Instagram home page and selecting “Post.” Videos can be up to 60 minutes in length.

How do you post longer videos on Instagram 2022?

Users can now simply upload videos up to 60 minutes long by tapping on the '+' at the top right corner of the home page. Video preview on the main page is now 60 seconds long and the preview is restricted to 15 seconds if it is eligible as an advertisement.


1 Answers

Try this :-

I am currently sharing my last saved video by this:-

    let fetchOptions = PHFetchOptions()
    fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    let fetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions)
    if let lastAsset = fetchResult.firstObject {
        let localIdentifier = lastAsset.localIdentifier
        let u = "instagram://library?LocalIdentifier=" + localIdentifier
        let url = NSURL(string: u)!
        if UIApplication.shared.canOpenURL(url as URL) {
            UIApplication.shared.open(URL(string: u)!, options: [:], completionHandler: nil)
        } else {

            let urlStr = "https://itunes.apple.com/in/app/instagram/id389801252?mt=8"
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)

            } else {
                UIApplication.shared.openURL(URL(string: urlStr)!)
            }
        }

    }
like image 144
iOS Developer Avatar answered Sep 22 '22 08:09

iOS Developer