xcode UIDocumentInteractionController 不再适用于 iOS6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12631466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:40:34  来源:igfitidea点击:

UIDocumentInteractionController no longer works in iOS6

iphoneobjective-cxcodeios6uidocumentinteraction

提问by Nick Pirollo

I have an app that shares with instagram built for iOS5 and now in iOS6, sharing no longer works although canOpenURLreturns true and code executes. The images are saved to the documents folder of the application with a .igoextension. This is passed to instagram with com.instagram.exclusivegram.

我有一个与为 iOS5 构建的 instagram 共享的应用程序,现在在 iOS6 中共享,尽管canOpenURL返回 true 并且代码执行,但共享不再有效。图像以.igo扩展名保存到应用程序的文档文件夹中。这通过 com.instagram.exclusivegram 传递给 instagram。

The code is below, it enters the if statement and displays "here in" but does not open the Share With dialog like it used to at the bottom of the screen.

代码如下,它进入 if 语句并显示“here in”,但不会像以前在屏幕底部那样打开 Share With 对话框。

        NSLog(@"%@", _imgToUpload);
        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            uidController = [[UIDocumentInteractionController alloc] init];
            //imageToUpload is a file path with .igo file extension
            uidController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:_imgToUpload]];
            uidController.UTI = @"com.instagram.exclusivegram";
            uidController.delegate = self;
            CGRect navRect = self.view.frame;
            [uidController presentOpenInMenuFromRect:navRect inView:[UIApplication sharedApplication].keyWindow animated:YES];
            NSLog(@"here in");
        }

_imgToUploadis providing the correct filepath as well.

_imgToUpload也提供了正确的文件路径。

Thank you, Nick

谢谢你,尼克

采纳答案by wsidell

Just did some testing and found a solution. Do not present in the keyWindow.

刚刚做了一些测试并找到了解决方案。不要出现在 keyWindow 中。

[uidController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];

I have tested this and it will fix the problem.

我已经对此进行了测试,它将解决问题。

回答by SundialSoft

Another reason for the uidocumentinteraction controller not working in iOS6 is that the new action sheet/launch panel (it shows apps available to open the doc) is now used. My app which worked fine launching iBooks with iOS5 failed because I launched from viewDidLoad which was now too early and I got an error on the current view controller 'whose view is not in the window hierarchy' so I changed my code to performselector after delay of 1 second. The app now calls iBooks via the new panel.

uidocumentinteraction 控制器在 iOS6 中不起作用的另一个原因是现在使用了新的操作表/启动面板(它显示可用于打开文档的应用程序)。我的应用程序运行良好,在 iOS5 上启动 iBooks 失败,因为我从 viewDidLoad 启动,现在还为时过早,我在当前视图控制器上出现错误“其视图不在窗口层次结构中”,所以我在延迟后将代码更改为 performselector 1秒。该应用程序现在通过新面板调用 iBooks。