IOS9 - Working with Instagram (w / hooks) does not work

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.

+8
ios objective-c ios9
source share
2 answers

After changing this line of code:

 NSURL *igImageHookFile = [[NSURL alloc] initFileURLWithPath:newJpgPath]; 

:

 NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath]; 

Now the Instagram feature for iOS 9 works. It seems that the previous line of code converting NSString to NSURL will put the "-: // file" at the end of the URL, which does not seem to register well with iOS 9. A simple conversion of NSString to NSURL without initializing as a URL file seems to be , working.

+17
source share

You must add a new key to your Info.plist file; this is a iOS 9 change for URL schemes. Check the first answer to this question: iOS 9 does not open Instagram app with SCHEME URL . And only FYI, iOS 9 changes the title “Open on Instagram” for the UIDocumentInteractionController to “Copy on Instagram”. I do not know why.

0
source share

All Articles