Instagram and cocos2d 2.x

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

instagramA quick method to send a photo to instagram

-(void)postInstagram
{
    AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];

    UIImage * screenshot = [self takeScreenShot];
    NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Screenshot.igo"];

    // Write image to jpeg
    [UIImageJPEGRepresentation(screenshot, 1.0) writeToFile:savePath atomically:YES];

    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];

    if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
    {
        UIDocumentInteractionController *documentInteractionController = [[UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]]retain];
        documentInteractionController.UTI = @"com.instagram.exclusivegram";

        documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Insert Caption here" forKey:@"InstagramCaption"];
        [documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:[app navController].view animated:YES];   
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>