princ___y
princ___y

Reputation: 1097

how to share image on instagram from native app ios 9.2?

i have tried this code but it shows error like

Warning: Attempt to present <_UIDocumentActivityViewController: 0x16acdc00> on which is already presenting <_UIDocumentActivityViewController: 0x16ae4800>

how to solve this??

-(IBAction)saveToInstagram:(id)sender {


        CGRect rect = CGRectMake(0 ,0 , 0, 0);
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.ig"];

        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
        NSLog(@"JPG path %@", jpgPath);
        NSLog(@"URL Path %@", igImageHookFile);
        self.docFile.UTI = @"com.instagram.photo";
        self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
        [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
        NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
        }
        else {
            NSLog(@"No Instagram Found");
        }



}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;
    return interactionController;
}

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {

}

Upvotes: 0

Views: 860

Answers (1)

tna0y
tna0y

Reputation: 1942

The problem is that while the first docfile is being presented you try to present the second one

// First presentation
[self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

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

        // Second presentation
        [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ]; 
}

I don't really understand why do you need to use the same method twice, but if you really do, then for the first presentation use animated: NO. I would suggest some kind of completion code block, but it appears that there is no such method for UIDocumentInteractionController

Upvotes: 2

Related Questions