您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

用 AppleScript 自動生成 iOS 配置描述文件

編輯:iOS 開發綜合

最近項目中需要用上 iPhone 的配置描述文件。

蘋果自帶了一款專門生成配置描述文件的工具——iPhone 配置描述工具(iPhone Configuration Utility),可以到蘋果官網查找,用它手動創建描述文件還算容易。

但由於項目需要,描述文件得根據請求內容自動生成,也就是要做成服務端動態生成,因此要用腳本自動化。目前卡在一個問題上:如何讓腳本獲取外部傳入的參數並加以利用,這部分還在研究中。

在 Mac 平台下,這類自動化通常要靠 AppleScript 腳本語言來完成。初次接觸,感覺 AppleScript 很不友好,語法頗為陌生,翻了一會兒文檔仍不知從何下手。網上資料也不多,東拼西湊之下,最終寫出了一個 WiFi 配置描述文件的腳本:

tell application "iPhone Configuration Utility"

set myconfigure to make new configuration profile with properties {displayed name:"heitan", profile identifier:"com.heitan.wifi"}

tell myconfigure

set mywifipayload to make new WiFi payload of myconfigure with properties {service set identifier:"heitan", password:"12345678"}

tell mywifipayload

make new trusted server certificate of mywifipayload with properties {certificate name:"heitan"}

end tell

end tell

export myconfigure to "~/testwifi"

end tell

補充幾個要點:

1、如何在終端運行 AppleScript 腳本?
命令:osascript scriptname(scriptname 為腳本名稱)

2、如何從執行命令中獲取傳入的參數?
命令:osascript scriptname heitan 12345678

on run argv

set username1 to text of "" & item 1 of argv & ""

set userpwd to text of "" & item 2 of argv & ""

end run

通過命令,即可動態創建 WiFi 配置描述文件。


  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved