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.