I am trying to upload video url on Instagram. after searching lots of code finally i comes to this code.
let url : NSString = "http://mobmp4.org/files/data/2480/Tutak%20Tutak%20Tutiya%20Title%20Song%20-%20Remix%20-%20Drunx%20-%20Mp4.mp4"
let urlStr : NSString = url.addingPercentEscapes(using: String.Encoding.utf8.rawValue)! as NSString
let videoURL : NSURL = NSURL(string: urlStr as String)!
print(videoURL)
let caption = "Some Preloaded Caption"
//let movieURL = NSURL.fileURL(withPath: moviePath, isDirectory: false)
let library = ALAssetsLibrary()
library.writeVideoAtPath(toSavedPhotosAlbum: videoURL as URL!) { (newURL, error) in
let instagramURL = NSURL(string: "instagram://library?AssetPath=\(videoURL)&InstagramCaption=\(caption.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed))")!
if UIApplication.shared.canOpenURL(instagramURL as URL) {
UIApplication.shared.openURL(instagramURL as URL)
}
}
but i got error like "fatal error: unexpectedly found nil while unwrapping an Optional value" at instagramURL variable.