2012-05-01 33 views
1

我正在Dashcode中編寫一個儀表板小部件,而在背面,我有一個信用字符串。我想在該字符串中包含小部件的版本號,但是如果可能的話,我想以編程方式從Info.plist中的CFBundleVersionCFBundleShortVersionString鍵中獲取它,以避免在更新小部件時必須在多個位置更改編號。儀表板小部件:從Info.plist中獲取版本號

搜索到的蘋果developer documentation,谷歌和各種論壇迄今已證明沒有結果。我想知道的是,是否有一種內置的方式可以做到這一點,蘋果包括但忘了提及(如var version = widget.version();什麼的),或者我的腳本是否必須在拔出之前拉入並解析整個plist我真正想要的一個價值。

感謝您提供任何幫助!

回答

1

我似乎找到了答案:使用Dashcode的「數據源」工具來讀取Info.plist中的XML數據源。從那裏,this blog post向我展示瞭如何遍歷plist中的結構,並得到正確的字符串(在這種情況下,文件中的第五<string>元,對應CFBundleShortVersionString

我結束了與功能:

function getWidgetVersion() { 
    var dataSource = dashcode.getDataSource("infoPlist"); 
    var version = dataSource.selection().valueForKey("dict").valueForKey("string")[4]; // This line and the previous could probably be combined for the sake of brevity 
    if (typeof(version) == 'string') { 
     document.getElementById("creditsLabel").innerHTML += version; //I'll change this to just pass the number on 
    } 
} 

由於creditsLabel div的文本已經以本地化的字符串開頭,因此我收到一個很好的標籤,上面寫着「版本1.0」。