Reputation: 1123
I use the following code in my iOS app to use Instagram iPhone hooks to post a photo to Instagram. I only want the "Open In..." menu to have Instagram app, no other apps. But in my case Camera+ also shows up. How can I restrict to Instagram?
Also, can I directly open Instagram instead of showing Open In menu?
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imageToUpload]];
self.documentInteractionController.UTI = @"com.instagram.photo";
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
[self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.exportBarButtonItem animated:YES];
}
Upvotes: 12
Views: 21982
Reputation: 8085
You can get the solution from this link.
Save image with the .igo
extension instead of .ig
. This is the "exclusive" version of the filetype.
Create a UIDocumentInteractionController
, then assign the value com.instagram.exclusivegram
to the property UTI
.
Present your UIDocumentInteractionController
with presentOpenInMenuFromRect:inView:animated
.
Upvotes: 8
Reputation: 470
BTW Instagram added an exclusive file extention (ig) and UTI (com.instagram.exclusivegram) for this. It still opens the Open with... menu but the only option is Instagram.
More info here: https://instagram.com/developer/mobile-sharing/iphone-hooks/
Upvotes: 12
Reputation: 149
This worked for me, do it like this and you will have only Instagram as the exclusive app to open your image.
NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// *.igo is exclusive to instagram
NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"];
NSData *imageData = UIImagePNGRepresentation(filteredImage);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
_docController=[[UIDocumentInteractionController alloc]init];
_docController.delegate=self;
_docController.UTI=@"com.instagram.photo";
[_docController setURL:imageURL];
_docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:@"#yourHashTagGoesHere",@"InstagramCaption", nil];
[_docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Upvotes: 4
Reputation: 1421
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];
self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl];
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
use this code in same sequence . here documentInteractionController is object of UIDocumentInteractionController.just for your knowledge. you will get instagram only in "open in" window.
Upvotes: 0
Reputation:
To answer only your first question: you may probably be able to restrict the "Open in ..." menu to just showing Instagram for your device (by deleting the Camera+ App, for example), but you won't be able to restrict users that install your app to their devices. And that's because the iPhone recognizes which applications are able to open a specific kind of files and it automatically show every one that does.
Upvotes: 0