I've been trying to create a sharing experience for our app where Instagram launches giving these two options:
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)
}
}
Tap below the photo or video in Feed. Tap Add post/video/reel to your story. Tap in the bottom right. Tap Share.
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.
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.
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)!)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With