1

I'm trying to share a photo to Instagram. So far my method is like this:

- (void)shareToInsta:(UIImage *)finalImage
{
    NSString *savePath = [NSHomeDirectory() stringByAppendingString:@"Documents/instagramTmp.igo"];
    [UIImageJPEGRepresentation(finalImage, 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"com.instagram.exclusivegram";
    _documentInteractionController.delegate = self;

    [_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}

The Instagram option is presented in UIDocumentInteractionController, but when I choose it, nothing happens. Anyone knows what I'm doing wrong?

PS: I'm already using a method just like this, but for WhatsApp, and it works just fine.

holex
  • 23,961
  • 7
  • 62
  • 76
Lucas Domene
  • 284
  • 1
  • 2
  • 16

1 Answers1

0

Save the file is wrong

- (void) saveimage:(UIImage*)image
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"save.igo"];
    NSData *imageData = UIImagePNGRepresentation(image);
    [imageData writeToFile:savedImagePath atomically:NO];
}

and

NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/save.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];