2015-10-16 63 views
1

我有一個應用程序包(使用Unity 3d構建,如果相關的話)我可以使用productbuild創建.pkg安裝程序並在App Store上發佈而不會出現問題。但是,應用程序會下載和緩存大量媒體,並且需要在機器上的所有用戶之間共享一些可選的配置文件。根據Apple's documentation,配置文件應該放在/ Library/Application Support目錄和/ Library/Caches中的媒體中。我做了一個應用程序的修改版本,它使用這些目錄而不是沙盒應用程序可以訪問的目錄,但它沒有對/ Library目錄的權限,除非我以root身份運行該應用程序,而不是現實的選擇。來自Mac App的訪問權限/庫/應用程序支持權限

我搜索了幾個小時谷歌,但我似乎無法找到任何有關創建這樣的安裝程序。我讀了this answer,它有一個安裝程序的屏幕截圖,它可以爲所有用戶安裝,但是我缺少一些選項來啓用它,或者屏幕截圖只是過時的,因爲我似乎無法創建一個.pkg給了我這個選擇。

所以我想我的問題歸結爲:我如何打包我的應用程序,以便它可以爲所有用戶安裝,並有權限讀/寫/庫/應用程序支持/ {應用程序名稱},或者是還有另一種在同一臺計算機上的多個用戶之間共享配置文件和/或媒體的首選方式?

回答

2

對於有類似問題的其他人,正確的答案是你不能使用productbuild來做到這一點,但你可以使用pkgbuild。

我爲App Store productbuild生成步驟是這樣的:

productbuild --component "{mystoreapp.app/}" /Applications --sign "{signing identity}" "{mystorepkg.pkg}" 

的PKGBUILD相應的包裝命令如下:

pkgbuild --component "{mymodifiedapp.app/}" --sign "{signing identity}" --ownership preserve --scripts "{path/to/my/scripts}" --identifier {com.yourcompany.yourapp} --version "{versionNumber}" --install-location /Applications "{mymodifiedpkg.pkg}" 

注意簽署是可選在這裏,因爲它會在店外散發。其中{路徑/要/我的/腳本}有一個文件名爲它postinstall,看起來像這樣:

#this function creates a directory if it doesn't exist 
create_directory() { 
    if [[ ! -d "$1" ]] 
    then 
      if [[ ! -L "$1" ]] 
      then 
        echo "directory $1 doesn't exist. Creating now" 
        mkdir "$1" 

        echo "directory $1 created" 
      else 
        echo "directory $1 exists" 
      fi 
    fi 
} 

#this function gives all users read and write (and execute) access to the directory 
fix_dir_permissions() { 
    chmod 777 "$1" 
} 

baseDirName="/Library/Application Support/{your app name bere}" 

subDirs[0]="$baseDirName/{sub dir here}" 

#create base directory 
create_directory "$baseDirName" 

#create all subdirectories and give permissions 
for subDir in "${subDirs[@]}" 
do 
    create_directory "$subDir" 
    fix_dir_permissions "$subDir" 
done 

exit 0 

這個腳本後,將運行安裝已經結束,將創建應用程序的支持目錄,以及任何您需要的子目錄並更改它們的權限,以便所有用戶都可以訪問它們。