Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仪表板小部件:从Info.plist获取版本号_Javascript_Macos_Widget_Dashboard_Dashcode - Fatal编程技术网

Javascript 仪表板小部件:从Info.plist获取版本号

Javascript 仪表板小部件:从Info.plist获取版本号,javascript,macos,widget,dashboard,dashcode,Javascript,Macos,Widget,Dashboard,Dashcode,我正在用Dashcode编写一个仪表板小部件,在背面,我有一个用于积分的字符串。我希望在该字符串中包含小部件的版本号,但如果可能,我希望通过编程方式从CbundLeverVersion或CbundleShortVersionString输入Info.plist中获取它,以避免在更新小部件时在多个位置更改该编号 到目前为止,苹果、谷歌和各种论坛上的搜索结果都是徒劳的。我想知道的是,是否有一种内置的方法可以做到这一点,Apple包括但忘记了提及(比如var version=widget.versio

我正在用Dashcode编写一个仪表板小部件,在背面,我有一个用于积分的字符串。我希望在该字符串中包含小部件的版本号,但如果可能,我希望通过编程方式从
CbundLeverVersion
CbundleShortVersionString
输入Info.plist中获取它,以避免在更新小部件时在多个位置更改该编号

到目前为止,苹果、谷歌和各种论坛上的搜索结果都是徒劳的。我想知道的是,是否有一种内置的方法可以做到这一点,Apple包括但忘记了提及(比如
var version=widget.version();
或其他什么),或者我的脚本是否必须在提取出我真正想要的值之前拉入并解析整个plist


谢谢你能提供的任何帮助

我似乎找到了答案:使用Dashcode的“数据源”功能将Info.plist作为XML数据源读取。从那里,我演示了如何遍历plist的结构并获得正确的字符串(在本例中,是文件中的第五个
元素,对应于
CbundleShortVersionString

我最终得到的功能是:

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的文本已经以一个本地化字符串开始,我得到了一个很好的小标签,上面写着“Version1.0”。

我似乎找到了答案:使用Dashcode的“数据源”可以将Info.plist作为XML数据源读取。从中,我了解了如何遍历plist的结构并获得正确的字符串(在本例中,是文件中的第五个
元素,对应于
CbundleShortVersionString

我最终得到的功能是:

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的文本已经以一个本地化字符串开始,我得到了一个很好的小标签,上面写着“Version1.0”