presentOpenInMenuFromBarButtonItem:不会导致菜单出现 [英] presentOpenInMenuFromBarButtonItem: doesn't cause menu to appear

查看:26
本文介绍了presentOpenInMenuFromBarButtonItem:不会导致菜单出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 UIDocumentInteractionControllerpresentOpenInMenuFromBarButtonItem 显示打开方式菜单.这不会在屏幕上显示 UIDocumentInteractionController.奇怪的是,如果我用Options"替换OpenIn",那么它会按预期工作.

I am attempting to display an Open In menu via UIDocumentInteractionController and presentOpenInMenuFromBarButtonItem. This does not bring up the UIDocumentInteractionController on screen. The weird thing is that if I replace "OpenIn" with "Options" then it will work as expected.

是什么导致 presentOpenInMenuFromBarButtonItem 不起作用?谢谢.

What is causing presentOpenInMenuFromBarButtonItem not to work? Thank you.

    NSString *fileName = [NSString stringWithFormat:@"%@text.txt", NSTemporaryDirectory()];
    [self.textToShare writeToFile:fileName
                       atomically:NO
                         encoding:NSUTF8StringEncoding
                            error:nil];

    NSURL *textFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"text.txt"]];

    self.openInController = [UIDocumentInteractionController interactionControllerWithURL:textFileURL];
    self.openInController.delegate = self;
    [self.openInController presentOpenInMenuFromBarButtonItem:self.buttonToPresentFrom animated:YES]; //replacing OpenIn with Options causes it to appear

推荐答案

问题是 presentOpenIn... 仅在安装了可以打开您发送的文件的应用程序时才显示菜单.iOS Simulator 没有任何可打开 .txt 文件的应用程序,因此它似乎无法正常工作.如果你在物理设备上运行,它工作得很好.

The problem is that presentOpenIn... only displays a menu when there are apps installed that can open the file you're sending. iOS Simulator does not have any apps that open .txt files, so it didn't seem to be working. If you run on physical device, it works just fine.

我决定添加这个以获得更好的行为:

I decided to add this for better behavior:

BOOL didPresentOpenIn = [self.openInController presentOpenInMenuFromBarButtonItem:self.buttonToPresentFrom animated:YES];
    if (!didPresentOpenIn) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Apps Available"
                                                        message:@"You do not have any apps installed that can open text files."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }

这篇关于presentOpenInMenuFromBarButtonItem:不会导致菜单出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆