从UIDocumentInteractionController中选择App会抛出" LaunchServices:invalidationHandler,名为"错误

时间:2014-09-22 20:48:44

标签: ios objective-c ios8 instagram

出于一些非常奇怪的原因,当我尝试选择UIDocumentInteractionController中显示的应用程序时,没有任何反应。控制台正在记录LaunchServices: invalidationHandler called错误,我环顾四周试图找到修复程序,但我什么都没有。

以下是将应用中的照片发送到Instagram的代码。菜单弹出很好,并将Instagram显示为我想要的唯一选项,但是当我点击它时,除了前面提到的控制台消息之外没有任何其他事情发生。

- (void)addToInstagram
{
    // Save image to temporary file
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"add_to_insta.igo"];
    NSData *imageData = UIImagePNGRepresentation(self.energy.image);
    [imageData writeToFile:savedImagePath atomically:NO];
    NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/add_to_insta.igo"];
    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

    // Pass into Instagram app
    CGRect rect = CGRectMake(0, 0, 612, 612);
    self.docFile = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    self.docFile.UTI = @"com.instagram.exclusivegram";
    self.docFile.annotation = @{@"InstagramCaption": @"#capturedby_____"};

    [self.docFile presentOpenInMenuFromRect:rect inView:self.view animated:YES];
    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"instagram://media?id=MEDIA_ID"]]){
        [self.docFile presentOpenInMenuFromRect:rect inView:self.view animated:YES];
    }else{
        UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Instagram" message:@"You do not have Instagram installed." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [errorView show];
    }
}

有没有其他人偶然遇到过这个错误?

2 个答案:

答案 0 :(得分:0)

您是否尝试过设置UIDocumentInteractionController委托?我收到相同的消息,但设置委托允许显示文档选择器。

答案 1 :(得分:0)

尝试将此行添加到主线程中:

      dispatch_async(dispatch_get_main_queue(), ^() {

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

      });