Swift macos アプリでファイルパーミッションエラーになる(App Sandboxの制御)

SwiftでDownloadフォルダのファイル名を変えようとすると、パーミッションエラー

try FileManager.default.moveItem(atPath: oldPath, toPath: newPath)

以下赤字のようなエラー

RENAME:/Users/hirotoyagi/Downloads/apache_tomcat/tomcat4/with_iis.html -> /Users/hirotoyagi/Downloads/apache_tomcat/tomcat4/with_iis.html.origin
Error Domain=NSCocoaErrorDomain Code=513 ““with_iis.html couldnt be moved because you dont have permission to access tomcat4”.” UserInfo={NSSourceFilePathErrorKey=/Users/hirotoyagi/Downloads/apache_tomcat/tomcat4/with_iis.html, NSUserStringVariant=(
 Move
), NSDestinationFilePath=/Users/hirotoyagi/Downloads/apache_tomcat/tomcat4/with_iis.html.origin, NSFilePath=/Users/hirotoyagi/Downloads/apache_tomcat/tomcat4/with_iis.html, NSUnderlyingError=0x6000035d3840 {Error Domain=NSPOSIXErrorDomain Code=1 Operation not permitted”}}

App Sandbox

Mac App Store を介して macOS アプリを配布するには、アプリのサンド ボックス機能を有効にする必要があります。

制御するには、以下、Signinig & Capabilities -> App Sandbox -> File Access Type で適当なところに権限を設定する

macos_app_permission.png

Follow me!

コメントを残す

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