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

How to set up Kiosk Mode for Mac apps?

我正在尝试使应用程序以演示模式启动,同时禁用 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 行我收到错误:

Type of expression is ambiguous without more context

谁能帮我找到解决方案并解释错误的含义。

同样在 browserWindowController 行我得到错误:

Use of unresolved identifier 'browserWindowController'

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

With 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 编译器不知道这个变量是什么。它可能已经在其当前使用范围之外定义,甚至根本没有声明。

我已经更新了 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 是您要在其中使用信息亭模式的 window。