为什么 UIDocumentinteractioncontroller 不显示菜单?

发布于 2024-11-17 14:20:18 字数 1031 浏览 7 评论 0 原文

有一段时间我正在努力创建一个定制的钛模块。我正在尝试在其他应用程序中打开 pdf。 一切似乎都是正确的(没有警告等) 但按下导航栏中的按钮时没有显示菜单。

这是显示菜单的方法的代码:

ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);

TiViewProxy* viewAnchor = [args objectForKey:@"view"];
NSString* fileToOpen = [args objectForKey:@"url"];



NSLog(@"%@",fileToOpen);

if(viewAnchor != nil){
    NSLog(@"viewAnchor is not nil accessing controller");
    NSLog(@"%@",[TiUtils toURL:fileToOpen proxy:self]);

    CGRect rect = [TiUtils rectValue:args];
    self.controller = [[UIDocumentInteractionController interactionControllerWithURL:[TiUtils toURL:fileToOpen proxy:self]] retain];
    self.controller.delegate = self;

    BOOL menuDisplayed = [self.controller presentOpenInMenuFromBarButtonItem:[viewAnchor barButtonItem] animated:YES];

    //menuDisplayed = YES
    if(menuDisplayed)
    {
        NSLog(@"Menu is displayed");
        //This display's com.adobe.pdf
        NSLog(@"%@",self.controller.UTI);
    }
    else
    {
        NSLog(@"Menu failed to display");
    }
}

For a while I'm strugeling creating a custom titaniummodule. I'm trying to open a pdf in an otrher app.
Everything seems to be correct (no warnings etc)
But there is no menu showing when pressing the button in de navBar.

Here is the code of the method showing the menu:

ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);

TiViewProxy* viewAnchor = [args objectForKey:@"view"];
NSString* fileToOpen = [args objectForKey:@"url"];



NSLog(@"%@",fileToOpen);

if(viewAnchor != nil){
    NSLog(@"viewAnchor is not nil accessing controller");
    NSLog(@"%@",[TiUtils toURL:fileToOpen proxy:self]);

    CGRect rect = [TiUtils rectValue:args];
    self.controller = [[UIDocumentInteractionController interactionControllerWithURL:[TiUtils toURL:fileToOpen proxy:self]] retain];
    self.controller.delegate = self;

    BOOL menuDisplayed = [self.controller presentOpenInMenuFromBarButtonItem:[viewAnchor barButtonItem] animated:YES];

    //menuDisplayed = YES
    if(menuDisplayed)
    {
        NSLog(@"Menu is displayed");
        //This display's com.adobe.pdf
        NSLog(@"%@",self.controller.UTI);
    }
    else
    {
        NSLog(@"Menu failed to display");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

调妓 2024-11-24 14:20:18

模块方法在非 UI 线程上运行,但是,所有 UIKit 方法必须在主 UI 线程上执行。您需要确保您的方法使用宏在 UI 线程上运行:

ENSURE_UI_THREAD_1_ARG(args);

更多详细信息:

https://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide#iOSModuleDevelopmentGuide-AddingSpecialCompilerDirectives

Module methods run on a non-UI thread, however, all UIKit methods must be executed on the main UI thread. You need ensure that your method is running on the UI thread with the macro:

ENSURE_UI_THREAD_1_ARG(args);

More details on:

https://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide#iOSModuleDevelopmentGuide-AddingSpecialCompilerDirectives

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文