ContentSync.sync({id: "...", type: "local", src: "") fails to call callback on iOS
Opened this issue · 3 comments
Expected Behaviour
When using
sync = ContentSync.sync({id: "...", type: "local", src: ""); sync.on("error", function() {...});
on Android, the error handler gets called when there is no synced content yet.
(I believe I read somewhere in the docs that this is the suggested method to test if there is synced content already available, but I didn't find this anymore. Is this still correct usage?)
Actual Behaviour
On iOS, the same code hangs, as no handler is called at all. I would expect that also the error handler is called in this case.
Reproduce Scenario (including but not limited to)
see above
Steps to Reproduce
see above, in my case this behaviour can be reproduced every time
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
iOS 9.3.5
(Android) What device vendor (e.g. Samsung, HTC, Sony...)
iPod touch
Cordova CLI version and cordova platform version
cordova --version # 8.0.0
cordova platform version ios # 4.5.4
Plugin version
cordova plugin version | grep phonegap-plugin-contentsync # 1.4.2
Sample Code that illustrates the problem
sync = ContentSync.sync({id: "...", type: "local", src: "");
sync.on("complete", function() { console.log("complete") });
sync.on("error", function() { console.log("error") });
Logs taken while reproducing problem
The last thing I see in the logs is the message "Requesting local copy of ".
Actually I stepped through the sync:
method in ContentSync.m but I didn't figure out at which point the callbacks should be called.
There is a "Sync...." callback registered in the JS part, however (if you inspect cordova.callbacks
.
With phonegap-plugin-contentsync v1.3.6 it is working as I expect
The docs say at https://github.com/phonegap/phonegap-plugin-contentsync#working-with-the-native-file-system that I can use this code to get the local filesystem path:
var sync = ContentSync.sync({
src: 'https://myserver/app/1',
id: 'app-1'
});
sync.on('complete', function(data) {
window.resolveLocalFileSystemURL("file://" + data.localPath, function(entry) {
// entry is a DirectoryEntry object
}, function(error) {
console.log("Error: " + error.code);
});
});
Does someone know if it is a supported usage of the plugin to use this with undefined src
to test if there is data already available (downloaded during a previous app start)?
I found the part in the docs https://github.com/phonegap/phonegap-plugin-contentsync#api
The type local returns the full path to the cached content if it exists or downloads it from options.src if it doesn't. options.src is not required if cached content actually exists.
So, I think this should work and the handler should be called.