As far as I know, you have to use com.instagram.photo to get the general options and com.instagram.exclusivegram for the documentinteractioncontroller's UTI if you really only want Instagram + use the correct extension .ig for general and .igo for exclusive Instagram.
For some reason, I see multiple options and not just Instagram like I want to..
Did I forgot something? Is it done differently?
UIImage *image = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
CGRect rect = CGRectMake(0,0,0,0);
CGRect cropRect=CGRectMake(0,0,612,612);
// ig voor gewone instagram, igo voor exclusive instagram
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/temp/photo.igo"];
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
UIImage *img = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef);
[UIImageJPEGRepresentation(img, 1.0) writeToFile:jpgPath atomically:YES];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",jpgPath]];
// exclusive zou direct in de instagram app moeten openen, helaas toont hij meerdere opties met instagram ergenes helemaal achteraan
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
self.documentInteractionController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Alweer een Nostalgie deelnemer! #nostalgiebusje" forKey:@"InstagramCaption"];
[self.documentInteractionController presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
Using the file extension igo
is correct, and the number of apps that will appear in the list is considerably less than if you used ig
. From my testing (iOS 9 only), the UTI made no difference to the presented list.
Looks like the iPhone hooks doc is outdated.
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
self.documentInteractionController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
It seems that UTI string is overwritten by setupControllerWithURL:usingDelegate:
method.
You need to create a temporary copy of the image with a "ig" or "igo" extension, then share that with UTI "com.instagram.exclusivegram". This should present the DocumentInteractionController with only the Instagram option:
if (![fm fileExistsAtPath:tempDirectory])
[fm createDirectoryAtPath:tempDirectory withIntermediateDirectories:YES attributes:nil error:nil];
NSString *tempInstagramPath = [tempDirectory stringByAppendingPathComponent:@"instagramShare.igo"];
if ([fm fileExistsAtPath:tempInstagramPath])
[fm removeItemAtPath:tempInstagramPath error:nil];
[UIImageJPEGRepresentation(imageToShare, 1.0) writeToFile:tempInstagramPath atomically:NO];
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:tempInstagramPath]];
documentInteractionController.delegate = self;
documentInteractionController.UTI = @"com.instagram.exclusivegram";
documentInteractionController.annotation = @{@"InstagramCaption": @"My Photo Caption!"};
if (![documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated:YES])
NSLog(@"Cannot open Document Interaction Controller for sharing with Instagram");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With