I am currently updating one of my apps compatible with iOS9 and am having trouble sharing Instagram feature. I use Instagram hooks as indicated on their developer's site: ( https://instagram.com/developer/mobile-sharing/iphone-hooks/ )
The image I want to provide was generated successfully with the .igo extension, and the functionality still works as intended on iOS8. It seems to have broken with the new version of iOS.
Here is the code for sharing with Instagram using the UIDocumentInteractionController:
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { //convert image into .png format. NSData *imageData = UIImagePNGRepresentation(image); //create instance of NSFileManager NSFileManager *fileManager = [NSFileManager defaultManager]; //create an array and store result of our search for the documents directory in it NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create NSString object, that holds our exact path to the documents directory NSString *documentsDirectory = [paths objectAtIndex:0]; //add our image to the path NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //finally save the path (image) [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; CGRect rect = CGRectMake(0 ,0 , 0, 0); UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIGraphicsEndImageContext(); NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"]; NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave]; NSLog(@"jpg path %@",jpgPath); NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath]; NSLog(@"with File path %@",newJpgPath); NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath]; NSLog(@"url Path %@",igImageHookFile); self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; [self.documentController setDelegate:self]; [self.documentController setUTI:@"com.instagram.exclusivegram"]; [self.documentController presentOpenInMenuFromRect:rect inView:self.view animated:YES]; } else { NSLog (@"Instagram not found"); }
It may be worth mentioning that I already configured the URL schemes in the info.plist file, as required when changing iOS9.
It displays the UIDocumentInteractionController and has the option "Copy to Instagram". Pressing this option simply leads to the dismissal of the controller, while the log messages or breakpoints are not displayed in the delegate of the controller (set to self, view controller).
If someone has or had problems with this, it would be great to hear your thoughts or better yet, as it was decided.
Update
It is also worth mentioning that on the iOS8 device, the document interaction controller shows the "Open on Instagram" button. The iOS9 device shows the "Copy to Instagram" button.
ios objective-c ios9
Andy shephard
source share