0

我正在 Dashcode 中编写仪表板小部件,并且我想添加某种检查更新功能。我已经研究过 Sparkle,但 AFAICT 它不适用于这样的小部件。是否有一个常用的库来进行更新检查,还是我必须开发自己的系统?

我只需要一个非常简单的设置...自动检查新版本将是一个加分项,但如果用户必须单击一个按钮才能进行检查,这对我来说没问题。

4

1 回答 1

0

既然“有一个功能会......”那么我还没有遇到过它。

我所做的如下

在 plist 中有小部件的版本,你把数字放在那里,比如说 1.0。您应该能够访问和使用它。(见代码)因为我没有添加这个全局变量 widget_version = "1.4"; 然后在小部件更新时更新它。

然后在网络可访问的服务器上创建一个 php(或其他)文件,其中包含小部件当前版本的数量。再说一次 1.1。

然后你编写一个 javascript 函数,然后将这个当前的小部件版本与服务器版本进行比较,并显示一个图形或消息来告诉用户。最好让用户决定是否要升级而不是自动升级。

以下是我使用的代码。请随意复制和/或破解。

function getSoftwareUpdate() {

// so use the built in CURL to do a REST call n.b. in widget preference you will need to check 'allow network access'
var softwareUpdate = widget.system("/usr/bin/curl  'http://api.yourserver.com/widget/wfccupdate.php'", null).outputString;

//alert(softwareUpdate); // tells you the function has been called
//alert("the update number from the REST " + softwareUpdate); // for debugging will show the key

// in main.js add this line
// var widget_version = "1.4"; // this is changed when you update the widget code for  new release
// yes it's a global variable and bad but i was in a hurry
// the following line should get the widget number but for some reason i didn't do it
// localVersion = widget.preferenceForKey(preferenceForKey);
//alert("the internal preference key " + widget_version);

// then check to see if they match
    if(softwareUpdate == widget_version)
    { hide_update('softwareupdate')
    }
    else
    {show_update('softwareupdate')
    }
}

function hide_update(el) { // hide the update graphic
    if(document.getElementById(el)) 
    {
        if(document.getElementById(el).style.display != "none") 
        document.getElementById(el).style.display = "none";
    }
}
function show_update(el) { // show the update graphic
    if(document.getElementById(el)) {
        if(document.getElementById(el).style.display == "none") 
        document.getElementById(el).style.display = "block"; 
        }
    }



// this is the php that is called by curl and acts as REST

<?php
// data
$UPDATE_database = <<<_UPDATE_
<?xml version="1.0" encoding="utf-8" ?>
<update>
    <widgetversion>1.1</widgetversion>
</update>
_UPDATE_;

// load data
$xml = simplexml_load_string($UPDATE_database);
$result = $xml->xpath("widgetversion");
print $result[0];
?>

希望这可以帮助

于 2010-12-11T11:19:14.907 回答