ios - 使用 Instagram 的 UIDocumentInteractionController 时发送到已释放实例的消息

标签 ios instagram uidocumentinteraction

我正在使用 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/

相关文章:

javascript - Instagram 身份验证 API 不返回访问 token

ios - Instagram 和 iOS。与当前用户获得很多喜欢的照片

ios - 文档交互 Controller

ios - 在另一个应用程序中打开文件时更改 UIDocumentInteractionController 中的文件名

ios - UIDocumentInteractionController 不适用于 Instagram

iOS 需要一个表达式

ios - 根据通知数量增加角标(Badge)值

php - Laravel 5 上的 Instagram 集成

ios - 将 GoogleAnalytics header 导入 Swift 框架?

ios - 在 iPhone 6+ 上无法获取 View 以使用整个屏幕宽度