phonegap / phonegap-plugin-contentsync

Download and cache remotely hosted content
Apache License 2.0
206 stars 98 forks source link

Full working sample #137

Open ghost opened 8 years ago

ghost commented 8 years ago

Can anyone give an full working example for downloading, extracting und redirecting to the extracted content?

imhotep commented 8 years ago

Yes here

ghost commented 8 years ago

It work's finde, but when i restart the app, the old local content appears.

macdonst commented 8 years ago

@realn3rd correct. In the app start up you'd need to check if there is content at the synched location and load your app from there instead.

imhotep commented 8 years ago

Right. The plugin doesn't manage content for you. It just syncs content to store it to some permanent location. There are different ways you can manage content and it's up to you how you want to do that.

ghost commented 8 years ago

How can I add a simple test routine to the app?

ghost commented 8 years ago

any idea?

imhotep commented 8 years ago

@realn3rd what do you mean by simple test routine ?

ghost commented 8 years ago

A simple way to test on app start if content were already downloaded und redirect to this content.

ghost commented 8 years ago

Maybe something at device-ready-event?

imhotep commented 8 years ago

@realn3rd Yes you can call something when deviceready fires

For example:


document.addEventListener('deviceready', function() {
   // this downloads your app if it doesn't exist OR immediately returns a path to your app if it had been previously downloaded
   // the `src` option is not required if you know that your app was previously downloaded.
   var sync = ContentSync({src: "...", id: "...", type: "local"});
   sync.on('complete', function(data) {
      // data.localpath will point to your app
   });
});
ghost commented 8 years ago

Nice, but it doesn't work :/

imhotep commented 8 years ago

What doesn't work ? Could you be more specific ?

ghost commented 8 years ago

The App shows only the local content, not the cached after restarting it.

imhotep commented 8 years ago

@realn3rd did you set document.location=data.localpathin the complete callback ?

ghost commented 8 years ago

Yes http://pastebin.com/hsRCNKzA

ghost commented 8 years ago

Any idea?

imhotep commented 8 years ago

@realn3rd sorry for delay. You can try to use the following (on iOS 9+ and above) if you're using WKWebView:

ContentSync.loadUrl(YOUR_URL)

I've updated the sample in the repository to reflect this.