JPMartha's Pancake

This blog is the way to brush up my poor English.

Give an Image to Instagram app in Swift

I'm Martha.

I write an article in this blog for the first time.

This is based on the following my article.

I'd like to brush up my poor English. If there are some mistakes in my English, please feel free to correct them.


This article describes the Instagram's sharing flow in Swift.


It doesn't describe the way to post photos on Instagram directly using the Instagram API.


  • I use Instagram on my personal life, so I tried coding.
  • It seems that few libraries have only this function.
  • I'd like to introduce my library.

Getting started

Save the file in PNG or JPEG (preferred) format. Two combinations of filename extension and UTI is given. I recommend the latter, because of displaying unnecessary icons.

filename extension UTI
.igo com.instagram.exclusivegram

Use the UIDocumentInteractionController to give it to Instagram app.


On your application Info.plist, add the LSApplicationQueriesSchemes key.

Key Type Value
LSApplicationQueriesSchemes Array instagram

Write your image data to a file in tmp directory.

let imageData = UIImageJPEGRepresentation(YourImage, 1.0)
let temporaryDirectory = NSTemporaryDirectory() as NSString
let temporaryImagePath = temporaryDirectory.stringByAppendingPathComponent("YourImageFileName.igo")
let boolValue = imageData.writeToFile(temporaryImagePath, atomically: true)

Create an instance of the UIDocumentInteractionController class.

lazy private var documentInteractionController = UIDocumentInteractionController()

Set the URL property and the UTI property, and call the presentOpenInMenuFromRect method to display the menu.

documentInteractionController.URL = temporaryImagePath
documentInteractionController.UTI = "com.instagram.exclusivegram"
    inView: YourView,
    animated: true

The rest is a operation on your iOS device. Tap the "Copy to Instagram" icon, and Instagram app is presented with its filter screen.

Introduction my library



This library has functions at the very least, but I'd like to announce right now not to make mistakes.


I've referenced the following articles. Thanks!

Related to Instagram

Related to Carthage

Related to CocoaPods


I've used the following Web application for creating an animation GIF. Thanks!