Question

Thanks to a couple other posts here , I've successfully be able to use the Instagram iPhone hooks to open Instagram and present it with a photo successfully from my application.

(I've made my ViewController class a delegate of UIDocumentInteractionController, and alloc/init'ed a nonatomic/retain property of UIDocumentInteractionController...

However, the key that I put into my NSDictionary that I place in the document controller annotation property will not seem to carry over to Instagram - the caption area is just empty.

How do I deal with this?

Here is my method:

- (void) uploadImageToInstagram:(UIImage *)imageToUpload {
    NSLog(@"postToInstagramInBackground");

    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {

        // Upscale to 612x612
        imageToUpload = [self upscaleImage:imageToUpload];

        // Get JPG + IGO Format
        NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/generate.igo"];
        [UIImageJPEGRepresentation(imageToUpload, 1.0) writeToFile:savePath atomically:YES];

        // Paths
        NSURL *imageURL = [NSURL fileURLWithPath:savePath];
        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]];

        // Setup DocController
        self.docController.UTI = @"com.instagram.photo";
        self.docController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        self.docController.annotation = [NSDictionary dictionaryWithObject:@"MyApp" forKey:self.caption.text];
        [self.docController setURL:imageURL];
        [self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES ];
    }
    else {
        NSLog(@"Instagram not installed in this device!\nTo share image please install Instagram.");
    }
}

There are a few methods that are called here that I haven't included, one that upscales the image to make sure its 612x612, and one setups the file url for the document controller.

Was it helpful?

Solution

Proper syntax should be

self.docController.annotation = [NSDictionary dictionaryWithObject:self.caption.text forKey:@"InstagramCaption"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top