For sharing/posting image to Instagarm, you should have two things
1. Instagram should be installed on your device.
2. User must be logged-in onto Instagram app prior to sharing/Posting image.
NOTE:- If user is not logged in then you have to log him/her in first and then allow him to open your app and re share it.
For sharing image to Instagram, first we created an image with extension .igo(its instagram file extension so that the Instagram app can be shown in UIDocumentController) then save it to our document directory by first removing any image the already written on that location and re writing new image using writeToFile method, that we are going to share to Instagram. Then we will create our UIDocumentController instance and gave it the path of our sharing image that we wrote in document directory. After finish this, we have to specify app identifier to let compiler know which app is capable of opening .igo type document, here we gave “com.instagram.exclusivegram“. Lastly, we present our UIDocumentController to user.
Below is the code for above explanation