Root Fetcher plugin not working for iOS

I would like to implement this plugin: https://github.com/christocracy/cordova-plugin-background-fetch . I installed the plugin using the CLI and then copied the BackgroundFetch.js file to my www directory and referenced it in index.html. I have placed the sample code given in the git url in the DeviceReady function. However, on startup, I ran into the error:

TypeError: 'undefined' is not an object (evaluate "Fetcher.configure")

Can someone please tell me why this is happening? I have tried for two days now but to no avail. Any help would be appreciated. Thanks in advance!  


EDIT1: Sorry I didn't mention this before, I created a cordova project using the command line and added the plugin as described above and then ran it on both the iOS Simulator and iPhone 4S. Both give the same error. I wrapped the code in a try-catch block and warned about an error, it was an error.

After seeing Clawish's suggestion, I removed the js file and link to it and then removed and added the plugin again. Now I don't get any errors, but I can't see "CDVBackgroundFetch configure" in the logs. If I simulate a background selection on the simulator, I get the error: -

CDVBackgroundFetch onFetch
Warning: Application delegate received a call to -app: execute FetchWithCompletionHandler : but no completion handler was called.

Where am I going wrong? I haven't made any changes to the code other than adding example code to call Fetcher.configure in onDeviceReady  


EDIT2:

After seeing the second edit of Clawfish, I removed the service call and shortened the function as shown below:

onDeviceReady: function() {
app.receivedEvent('deviceready');

var Fetcher = window.plugins.backgroundFetch;

// Your background-fetch handler.
var fetchCallback = function() {
    console.log('BackgroundFetch initiated');
    Fetcher.finish();
}
Fetcher.configure(fetchCallback);
},

      

However, I don't see any log messages saying "CDVBackgroundFetch Configuration" and when simulating Background fetch, the same warning appears as above. It seems like part of Fetch gets executed without running configure in the first place.

+3


source to share


1 answer


Edit2: I think you've added all the sample code from the docs (with decryption var Fetcher

and handler var fetchCallback

and after declaring both, you run Fetcher.configure(fetchCallback);

. The problem may be that you don't have the jQuery your referenced index.html

and the code stops working when it sees the line $.get(...)

If so, download jQuery, put it in your folder www

and link to it from yours index.html

. Do you see the console message console.log('BackgroundFetch initiated');

? How about /heartbeat.json

, did you change that?


Edit: You don't need to copy BackgroundFetch.js to the directory www

, and you also don't need to link to it in index.html

. Try to remove the link in yours index.html

and leave the plugin files intact after installation. If you have changed something regarding the file structure, you should cordova plugin remove

plug in add

again after that.




I don't know which console you are getting this error from. If it's a browser console like Chrome, then there is no miracle, since Fetcher only works with an iDevice (or iOS simulator). The Cordova Console plugin does not print such messages.

Try using the code in the iOS simulator.

+1


source







All Articles