Maysam Maysam - 6 months ago 227
Swift Question

Add Instagram to UIActivityViewController

I'm trying to share an image using standard

UIActivityViewController
, it's fine to share on Facebook, Twitter and Save Image using this code:

let firstActivityItem = "foo text"
let secondActivityItem : UIImage = image!

let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem], applicationActivities: nil)

activityViewController.excludedActivityTypes = [
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeAddToReadingList,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo
]

self.presentViewController(activityViewController, animated: true, completion: nil)


I need one more thing, Instagram:

If UIApplication.sharedApplication().canOpenURL(instagramURL!) {
// Success
var img = image!

var savePath: String = NSHomeDirectory().stringByAppendingPathComponent("Documents/Test.igo")
UIImageJPEGRepresentation(img, 1).writeToFile(savePath, atomically: true)
var imgURL = NSURL(string: NSString(format: "file://%@", savePath) as! String)
docController = UIDocumentInteractionController(URL: imgURL!) // 1
docController.UTI = "com.instagram.exclusivegram" // 2
docController.delegate = self
docController.annotation = ["InstagramCaption":"testsss"] // 3
docController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true) // 4
} else {
// Error
}


Both these codes work fine separately, how can I add Instagram to the
UIActivityViewController
? Is it possible at all?

Answer

It seems it's not possible, because of .igo extension which is needed by Instagram.