Introduction to the post programmatically share image to Instagram through iOS app
Instagram is another most popular social platform for sharing images. Now days, every app share image to Instagram too. Since like other social platforms Instagram does not provide developers permission to write image directly on the user Instagram wall. So for this we can use UIDocumentInteractionController provided in objective c and swift language in X-code.
For sharing/posting image to Instagram, 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.
Code for sharing image to Instagram through iOS app – objective C
Code for sharing image to Instagram through iOS app – Swift 3
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.