¿Hay una manera estándar para comprobar si hay actualizaciones en un widget de Dashboard?

StackOverflow https://stackoverflow.com/questions/4369055

  •  09-10-2019
  •  | 
  •  

Pregunta

Estoy escribiendo un widget de Dashboard en Dashcode, y me gustaría añadir algún tipo de funcionalidad de comprobación para la actualización. Ya he mirado en la chispa, pero AFAICT no lo es aplicable a los widgets de este tipo. ¿Hay una biblioteca comúnmente usado para hacer la comprobación de actualizaciones, o voy a tener que desarrollar mi propio sistema?

Sólo necesito una configuración muy sencilla ... comprobar automáticamente si hay nuevas versiones sería un plus, pero si el usuario tenía que hacer clic en un botón con el fin de comprobar que estaría bien conmigo.

¿Fue útil?

Solución

Dado que "no es una función que ...", entonces no he llegado a través de ella.

Lo que hice fue el siguiente

En el plist existe la versión del widget y se puso el número de allí, digamos 1.0. Que debe ser capaz de acceso y uso. (Ver código) Por razón por la que no lo hice, y añadió esta widget_version var mundial = "1.4"; y luego actualizado que cuando se actualiza el widget.

A continuación, en un servidor accesible por la web se crea un archivo php (o lo que sea) que tiene el número de versión actual del widget. Una vez más digamos 1.1.

A continuación, escribir una función de JavaScript que se verifique esta versión actual Reproductor en contra de la versión del servidor y visualizar un gráfico o un mensaje para indicar al usuario. Lo mejor es dejar que el usuario decida si quiere actualizar en lugar de lo que es automática.

siguiente es el código i utilizado. Por favor, copiar y cortar o como desee.

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];
?>

Espero que esto ayude

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top