Would it be possible to share a picture to Instagram bypassing the Action Share Sheet?
Please Note that I am aware of the UIDocumentInteractionController
and the hooks and in fact it works fine. With their sample code you get a Copy to Instagram
option (either unique if you use the exclusive UTI or a big list of apps which can handle a JPG/PNG, alongside with Instagram).
This works fine, but I'd like to know if there's a way to execute the action "Copy to Instagram" without the need to present the UIDocumentInteractionController
menu in iOS 9+.
For the record this is a simplified version of the code that works perfectly. Assuming you have a valid NSURL…
guard let data: NSData = NSData(contentsOfURL: url),
image = UIImage(data: data) else {
return
}
let imageData = UIImageJPEGRepresentation(image, 100)
let captionString = "caption"
let writePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("instagram.ig")
guard let _ = imageData?.writeToFile(writePath, atomically: true) else {
return
}
let fileURL = NSURL(fileURLWithPath: writePath)
self.documentController = UIDocumentInteractionController(URL: fileURL)
self.documentController.delegate = self
self.documentController.UTI = "com.instagram.photo"
self.documentController.annotation = NSDictionary(object: captionString, forKey: "InstagramCaption")
self.documentController.presentOpenInMenuFromRect(viewController.view.frame, inView: viewController.view, animated: true)
The problem is that this will present an "Action Sheet" and I want to avoid doing that if possible, I want to use instagram.ige
(or whatever the name it was to make it exclusive) and skip this ActionSheet.
Is that possible?
UPDATE: I haven't found a solution for this, but seems like Instagram finally is adding/added extensions: "Instagram recently added sharing extensions functionality to its iOS app. Now, you can share photos from third-party apps directly to Instagram" source: http://www.macworld.com/article/3080038/data-center-cloud/new-instagram-feature-for-ios-makes-it-easier-to-share-photos-from-other-apps.html
UPDATED Swift 4.2 CODE
Original Answer