Xcode Project Archives [Distribute App]ERROR ITMS-90296

com.apple.security.app-sandbox

macOS用アプリをApp Storeから配布する場合。Xcode メニューから[Project|Archives]をクリックでOrganizerが起動し[Distribute App]ボタンで「App Store Connect」に送信できます。普段macOSのアプリを作ってもApp Storeを使って配布することがなくて知らなかったんですが、”com.apple.security.app-sandbox”を設定しないと配布できないようでした。

ERROR ITMS-90296: "App sandbox not enabled. The following executables must include the "com.apple.security.app-sandbox" entitlement with a Boolean value of true in the entitlements property list: [( "com.mjeld.xxx.pkg/Payload/xxx.app/Contents/MacOS/xxx" )] Refer to App Sandbox page at https://developer.apple.com/documentation/security/app_sandbox for more information on sandboxing your app."

上記のエラーがでまして、Xcode アプリ[TARGET]のApp SandboxをONに変更して再度[Distribute App]すれば送信成功しました。

Swift ファイルやフォルダーをコピーする(copyItem)

FileManager copyItem

FileManagerを使えばファイルやフォルダーのコピーや削除が簡単にできます

let fileManager = FileManager.default
//コピー元指定 : ホームディレクトリのAフォルダー
let atUrl:URL = fileManager.homeDirectoryForCurrentUser.appendingPathComponent("A", isDirectory: true)
//コピー先指定 : /tmp/
let toUrl:URL = URL(fileURLWithPath: "/tmp/A")
do {
    print(atUrl)
    print(toUrl)
    try fileManager.copyItem(at: atUrl, to: toUrl)
} catch {
    print(error.localizedDescription)
}

コピー元は、homeDirectoryForCurrentUser(ホームディレクトリ)のappendingPathComponent()で指定したフォルダー名を指定しました。

コピー先は/tmpですcopyItem()のパラメータはURLなのでコピー元も先もURLになっています

コピー元にフォルダが無い場合は「The file “A” couldn’t be opened because there is no such file.」エラーになります。

copyItem()はフォルダの中にファイルやフォルダが入っていても簡単にコピーできます。

ファイルやフォルダを削除する

削除の場合は、removeItem()を使います。これも同じく引数はURL型です。

import Cocoa

let fileManager = FileManager.default
//削除指定 : /tmp/
let toUrl:URL = URL(fileURLWithPath: "/tmp/A")
do {
    print(toUrl)
    try fileManager.removeItem(at: toUrl)
} catch {
    print(error.localizedDescription)
}

ファイルもフォルダも同じです。フォルダの場合中身があってもサブフォルダがあっても削除できるようです。

2022 MJELD TECHNOLOGIES. ALL RIGHTS RESERVED