I am trying to share an image on the Instagram application through my application.
Please check my code below and please let me know where I have gone wrong.
_instagramURL = [NSURL URLWithString:[NSString stringWithFormat: @"instagram://media?id=%@",[SingletoneClass sharedSingleTone].imageId]];
if ([[UIApplication sharedApplication] canOpenURL:_instagramURL]) {
self.dic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[SingletoneClass sharedSingleTone].imagePath]];
self.dic.delegate = self;
self.dic.UTI = @"com.instagram.exclusivegram";
self.dic.annotation = [NSDictionary dictionaryWithObject:[SingletoneClass sharedSingleTone].captionStr forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect: CGRectZero inView:self.view animated:YES ];
}
else {
UIAlertController *alert = [[SingletoneClass sharedSingleTone] setAlertControllerWithTitle:@"" message:@"Instagram is not present in your device" andCallback:^(id actionResponse) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[self presentViewController:alert animated:YES completion:nil];
}
If above code is correct, then please let me know, from where I can find the imageId?
Finally, I got the solution. We need to save the image in Document directory. Instagram app can retrieve the image from Document directory.
Then by using UIDocumentInteractionController, we can share the image in Instagram app. Before sharing the image, you need to be sure that Instagram app is present in the device.
You can refer the following links for more information. https://www.instagram.com/developer/mobile-sharing/iphone-hooks/ and Share photo to Instagram from my iOS App