アプリを再び開くことができない状態を改善する

アプリレビューで以下のようなメッセージでリジェクトされることがあります。。

Design Preamble

The user interface of your app is not consistent with the macOS Human Interface Guidelines.

Specifically, we found that when the user closes the main application window there is no menu item to re-open it.

Next Steps

It would be appropriate for the app to implement a Window menu that lists the main window so it can be reopened, or provide similar functionality in another menu item. macOS Human Interface Guidelines state that "The menu bar [a]lways contains [a] Window menu".

Alternatively, if the application is a single-window app, it might be appropriate to save data and quit the app when the main window is closed.

For information on managing windows in macOS, please review the following sections in Apple Human Interface Guidelines:

* The Menu Bar and Its Menus
* The Window Menu
* The File Menu
* Clicking in the Dock
* Window Behavior

Please evaluate how you can implement the appropriate changes, and resubmit your app for review.

Please see attached screenshot for details.

→ 意訳

デザインの前提

あなたのアプリのユーザーインターフェースはmacOSユーザーインターフェースガイドラインに準拠していません。

特に、ユーザーがアプリを閉じたときに、再度起動するメニューがありません。

(以下省略)

メニューに新しいウィンドウを開くという項目がなく、ガイドラインに準拠していないという内容になります。これは結構忘れてしまいがちな対応です。 もし、再度アプリを起動しなくてもいい場合は以下のコードを書くことで赤いボタンを押したらすぐにアプリが終了するようにできます。

AppDelegate.swift内に記述

  func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
          NSApplication.shared.terminate(self)
          return true
  }

これでリジェクト対策になると思われます。 プロジェクトを作って最初に仕込んでおくと安心でしょう。

もし、赤いボタンで閉じてもアプリを終了せずに新規ウィンドウを開くという形を取りたい場合には、メニューに「新規ウィンドウ」の項目を追加してボタンをIBActionで接続し、新規ウィンドウを開くコードを記述するのが適切な方法となります。

MacOS $ sw_vers;xcodebuild -version;swift --version

ProductName:	macOS
ProductVersion:	11.4
BuildVersion:	20F71
Xcode 12.5.1
Build version 12E507
Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)
Target: x86_64-apple-darwin20.5.0

Category