【问题标题】:presentOpenInMenuFromBarButtonItem: doesn't cause menu to appearpresentOpenInMenuFromBarButtonItem:不会导致菜单出现
【发布时间】:2014-05-13 06:32:47
【问题描述】:

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

是什么导致presentOpenInMenuFromBarButtonItem 无法工作?谢谢。

    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

【问题讨论】:

    标签: ios objective-c uiactivityviewcontroller uidocumentinteraction uiactivity


    【解决方案1】:

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

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

    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];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-03
      • 2022-01-18
      • 2015-04-12
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 2015-12-12
      • 2020-03-18
      相关资源
      最近更新 更多