我正在使用 UIDocumentInteractionController
在 Instagram 上分享照片,我可以为其打开操作表(我不知道我应该调用什么),但是当我点击 在 Instagram 中打开
它只是崩溃,消息将是这样的,
*** -[UIDocumentInteractionController _openDocumentWithApplication:]: message sent to deallocated instance 0x1743762c0
请注意,我使用的是 ARC,并且还创建了 UIDocumentInteractionController
的强大属性。
为 UIDocumentInteractionController
添加了保留属性,
@property (nonatomic, retain) UIDocumentInteractionController *docController;
这是分享代码,
- (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.");
}
}
}
我在一个名为“ShareClass”的类中执行此操作,该类是 NSObject
的子类。
请注意,我已经检查了一些相同问题的答案,但它们是针对非 ARC 的,我也尝试将属性设置为 strong 或同时保留两者。这似乎不起作用。
最佳答案
最后,我通过我的自定义类的共享实例来解决它,它将通过应用程序保留并且不会释放任何实例。不确定是好是坏,但就像一个魅力。 ^_O
关于ios - 使用 Instagram 的 UIDocumentInteractionController 时发送到已释放实例的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27311965/