如何为 Mac 应用程序设置 Kiosk 模式?

问题描述 投票:0回答:3

我正在尝试使应用程序以演示模式启动,同时禁用 Dock、菜单栏、进程切换等。到目前为止,我有以下代码:

let presOptions: NSApplicationPresentationOptions =
        .HideDock                  |   // Dock is entirely unavailable. Spotlight menu is disabled.
    //  .AutoHideMenuBar           |   // Menu Bar appears when moused to.
    //  .DisableAppleMenu          |   // All Apple menu items are disabled.
        .DisableProcessSwitching   |   // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
        .DisableForceQuit          |   // Cmd+Opt+Esc panel is disabled.
        .DisableSessionTermination |   // PowerKey panel and Restart/Shut Down/Log Out are disabled.
        .DisableHideApplication    |   // Application "Hide" menu item is disabled.
    //  .AutoHideToolbar           |
        .FullScreen

let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: presOptions]

browserWindowController.containerView.enterFullScreenMode(NSScreen.mainScreen()!, withOptions: optionsDictionary)

在 .HideDock 行上,我收到错误:

如果没有更多上下文,表达类型不明确

有人可以帮我找到解决方案并解释错误的含义吗?

还在 browserWindowController 行上收到错误:

使用未解析的标识符“browserWindowController”

有人可以向我解释为什么这不起作用吗?

macos fullscreen swift2
3个回答
2
投票

对于 Swift 2

NSApplicationPresentationOptions
必须是一个数组:

let presOptions: NSApplicationPresentationOptions = [
    .HideDock,                     // Dock is entirely unavailable. Spotlight menu is disabled.
    //  .AutoHideMenuBar,           // Menu Bar appears when moused to.
    //  .DisableAppleMenu,          // All Apple menu items are disabled.
    .DisableProcessSwitching,      // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
    .DisableForceQuit,             // Cmd+Opt+Esc panel is disabled.
    .DisableSessionTermination,    // PowerKey panel and Restart/Shut Down/Log Out are disabled.
    .DisableHideApplication,       // Application "Hide" menu item is disabled.
    //  .AutoHideToolbar,           
    .FullScreen
]

至于

browserWindowController
错误,它只是意味着Swift编译器不知道这个变量是什么。它可能已在其当前使用范围之外定义,甚至根本没有声明。


1
投票

我已经更新了 swift 4.2 的代码。看看吧。

//Enter kiosk mode
func KisokMode(){
    let presOptions: NSApplication.PresentationOptions = [
        .hideDock,                     // Dock is entirely unavailable. Spotlight menu is disabled.
        .autoHideMenuBar,           // Menu Bar appears when moused to.
        .disableAppleMenu,          // All Apple menu items are disabled.
        .disableProcessSwitching,      // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
        .disableForceQuit,             // Cmd+Opt+Esc panel is disabled.
        .disableSessionTermination,    // PowerKey panel and Restart/Shut Down/Log Out are disabled.
        .disableHideApplication,       // Application "Hide" menu item is disabled.
        .autoHideToolbar,
        .fullScreen
    ]
    let optionsDictionary = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
    TheWindowExample.contentView?.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary) 
}

TheWindowExample 是您要在其中使用 kiosk 模式的窗口。


0
投票

如果有人在 SwiftUI 时代处理这个用例,我发现添加

<key>LSUIPresentationMode</key><real>3</real>

Info.plist 中将禁用全屏应用程序的菜单和停靠栏。

我在文档存档中找到了它,其中包含以下值描述。

全隐藏模式。在此模式下,所有 UI 元素都被隐藏,包括菜单栏。元素不会自动显示自己以响应鼠标移动或用户活动。

https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

它似乎仍然是活动文档的一部分:

https://developer.apple.com/documentation/bundleresources/information_property_list/lsuipresentationmode

© www.soinside.com 2019 - 2024. All rights reserved.