2010-12-06 7 views
0

私はDashcodeにDashboardウィジェットを作成していますが、何らかの種類のチェック・アップデート機能を追加したいと思います。私はすでにSparkleを調べましたが、AFAICTはこのようなウィジェットには適用できません。アップデート検査を行うためによく使用されるライブラリがありますか、私自身のシステムを開発する必要がありますか?ダッシュボードウィジェットで更新を確認する標準的な方法はありますか?

非常に簡単な設定が必要です...新しいバージョンの自動チェックはプラスになりますが、ユーザーがボタンをクリックして確認する必要がある場合は、それを確認してください。

答えて

0

「機能はありますか?」と言えば、私はそれを見つけられませんでした。 plistのでは

を次のように私は何

がウィジェットのバージョンがあり、あなたがそこに数値を入れて、1.0を言うことができますでした。あなたはアクセスして使用できるはずです。 (コードを参照してください)私はこのグローバル変数widget_version = "1.4"を追加しなかったため、理由はありません。ウィジェットが更新されたときにそれを更新しました。

次に、Webからアクセスできるサーバー上に、現在のバージョンのウィジェットを持つ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]; 
?> 

が、これは

を役に立てば幸い
関連する問題