Mac App Storeで配信するアプリがアクセス可能なディレクトリ

App StoreにサブミットしたMacアプリがリジェクトされてしまいました。リジェクト理由をみてみると、~/Library/Application Support/AppNameにアクセスしようとしているのが原因の様子。
参考資料として案内されていたFile System Usage Requirements for the App Storeによれば、アプリケーションがアクセスを許可されているディレクトリは下記の場所に限られています。

  1. Temporaryディレクトリ
  2. Libraryディレクトリの下記の場所
    1. ~/Library/Application Support/<app-identifier>
    2. ~/Library/<app-identifier>
    3. ~/Library/Caches/<app-identifier>
  3. ~/Musicや~/Picturesなど (音楽や画像などを扱うアプリケーションの場合)
  4. OpenPanel, SavePanelなどでユーザが指定したファイル

アプリケーション固有の設定で、NSUserDefaultsに入らないバイナリデータなど(ゲームデータや編集中のファイルの情報など)はこのうち2.のLibraryディレクトリにおく形になります。2のLibraryディレクトリの<app-identifer>については下記のような記述があり、アプリのBundle Identifierかアプリ名、会社名のいずれかに厳格にマッチしなければいけないようです。

<app-identifier> is your application’s bundle identifier, its name, or your company’s name. This must exactly match what is in iTunes Connect for the application.

今回のアプリケーションの場合、今まで配信していた有料アプリケーションの無料版を新たに追加リリースした形だったのですが、ここでapp-identifierが有料版と無料版で変更しなかったためにリジェクトされてしまった模様。というわけで、ここでは固定文字列でデータ保存先を決めるよりBundle Identifierを使う形でコーディングしておいたほうが良いですね。
ちょうどアップルのFile System Programming Guideにもこんなサンプルコードが乗っているので、これを使うのがよさそうですね。

- (NSURL*)applicationDataDirectory {
    NSFileManager* sharedFM = [NSFileManager defaultManager];
    NSArray* possibleURLs = [sharedFM URLsForDirectory:NSApplicationSupportDirectory
                                 inDomains:NSUserDomainMask];
    NSURL* appSupportDir = nil;
    NSURL* appDirectory = nil;
    if ([possibleURLs count] >= 1) {
        // Use the first directory (if multiple are returned)
        appSupportDir = [possibleURLs objectAtIndex:0];
    }
    // If a valid app support directory exists, add the
    // app's bundle ID to it to specify the final directory.
    if (appSupportDir) {
        NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
        appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
    }
    return appDirectory;
}

参考

  1. File System Usage Requirements for the App Store
  2. File System Programming Guide
Pocket

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です