1

I'm using UIDocumentInteractionController to share photo on Instagram, I am able to open action sheet (I don't know what should I call) for it, but when I tap on Open in Instagram it just crash, and message will be this,

*** -[UIDocumentInteractionController _openDocumentWithApplication:]: message sent to deallocated instance 0x1743762c0

For a note, I'm using ARC, and also created strong property of UIDocumentInteractionController.

Added retain property to UIDocumentInteractionController,

@property (nonatomic, retain) UIDocumentInteractionController *docController;

This is the code for sharing,

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

- (void) instagramShare {
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
    {
        NSString *filePath = [self saveAsIgoFile];
        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", filePath]];
        CGRect rect = CGRectMake(0, 0, 0, 0);
        self.docController = [self setupControllerWithURL:igImageHookFile usingDelegate:(id)_view];
        self.docController.UTI = @"com.instagram.photo";
        self.docController.annotation = [NSDictionary dictionaryWithObject:_titleToShare forKey:@"InstagramCaption"];
        [self.docController presentOpenInMenuFromRect:rect inView:_view.parentViewController.view animated:YES];
    }
    else
    {
        if(_block) {
            _block (_shareType, NO, @"Instagram not installed in this device!\nTo share photo/video please install Instagram application.");
        }
    }
}

I'm doing this in a class, named "ShareClass" which subclass of NSObject.

Note, I've checked some answers with the same issue, but they are for Non-ARC, also I tried setting property to strong or retain both. This doesn't seems to work.

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • how the `interactionDelegate ` is used here? Are you implementing the `documentInteractionControllerViewControllerForPreview:controller ` delegate method correctly? – Rukshan Dec 05 '14 at 09:04
  • This code works fine unless I didn't using it inside a custom class with a block. – Hemang Dec 05 '14 at 09:05
  • Above delegate method must return your presenting ViewController. Are you doing that correctly? – Rukshan Dec 05 '14 at 09:07
  • Yes, I think I'm doing it right, because after the code execution iOS show me a document controller with AirDrop (at Top) and Instagram app (at Bottom) with title, "Open in Instagram".. when I tap on the icon, then it'll leads to crash. – Hemang Dec 05 '14 at 09:14

1 Answers1

1

Finally, I sort it out by made shared instance of my custom class, that will remain through app and will not deallocated any instance. Not sure bad or good, but works like a charm. ^_O

Hemang
  • 26,840
  • 19
  • 119
  • 186