cordova-plugin-background-fetch: finished never been called

hi, first thanks for ur plugin i really appreciate ur hard work on it i tried this plugin with ios simulator where i needed to schedule local notification first time fires nicely and the local notification was scheduled perfectly but when i tried to do it again i got this message in xcode console

CDVBackgroundFetch AppDelegate received fetch event
2017-07-10 21:46:16.387 MyApp[28009:17544106] - TSBackgroundFetch performFetchWithCompletionHandler
2017-07-10 21:46:16.387 MyApp[28009:17544106] - CDVBackgroundFetch Rx Fetch Event
2017-07-10 21:50:34.740 MyApp[28009:17544106] CDVBackgroundFetch AppDelegate received fetch event
2017-07-10 21:50:34.740 MyApp[28009:17544106] - TSBackgroundFetch performFetchWithCompletionHandler
2017-07-10 21:50:34.741 MyApp[28009:17544106] Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called.
2017-07-10 21:50:34.741 MyApp[28009:17544106] - CDVBackgroundFetch Rx Fetch Event

what i can understand here that it might the finish() function wasnt called even though i put it inside configure function

if u can help me with this issue pls

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 29 (12 by maintainers)

Most upvoted comments

@ferreyes @christocracy unfortunately I never got it to work, even when I called BackgroundFetch.finish(), so I did something roundabout…feel free to comment and let me know if you find a solution

I call backgroundFetch.stop() on platform.resume when the app is being resumed and being used

and then I call backgroundFetch.configure when the app is paused. This actually re-initiates the backgroundFetch module each time the app is resumed/ paused.


    platform.resume.subscribe(()=>{
      backgroundFetch.status().then(val=>console.log(val))
      backgroundFetch.stop();
    })

    platform.pause.subscribe(() => {
      backgroundFetch.configure(config)
        .then(()=> {
          console.log('Background fetch callback called');
          this.localNotifications.schedule({
            title: 'test',
            text: 'test msg'
          })
         // Fetch activity coded here
          this.backgroundFetch.finish();
        })
        .catch(e => console.log('Error initializing background fetch', e));
    }
    )


Hello @sta55en

I have same issue with sending request. Chrome DevTools is showing requests in a ‘pending’ state and never finished. Do you figure out how can it be solved sending request by browser? If I am using cordova-plugin-advanced-http then it is working well.

Thank you

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a “discussion” and I will leave this open.

I’ve traced the adb logs and this is what I got:

From the log, after we see TSBackgroundFetch: - Background Fetch event received in the TSBackgroundFetch logs:

02-22 23:42:13.617  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : Posting heartbeat...                               │
02-22 23:42:13.617  4713  4713 I chromium: [INFO:CONSOLE(16234)] "Posting heartbeat...", source: http://localhost:8080/build/main.js (16234)                 │
02-22 23:42:13.617  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : Pushing 0 duty status events to server...          │
02-22 23:42:13.618  4713  4713 I chromium: [INFO:CONSOLE(16234)] "Pushing 0 duty status events to server...", source: http://localhost:8080/build/main.js (16│
02-22 23:42:13.618  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : Pushing 21 fixes to server...                      │
02-22 23:42:13.618  4713  4713 I chromium: [INFO:CONSOLE(16234)] "Pushing 21 fixes to server...", source: http://localhost:8080/build/main.js (16234)

The request to the API just sits there and hangs… If I call the code that hits the server from the UI while the app is open, it works 100%.

After we reopen the app, immediately, the request to the server completes. No errors anywhere in the log.

02-22 23:42:38.130   594  4287 D audio_hw_primary: enable_audio_route: usecase(1) apply and update mixer path: low-latency-playback speaker                  │
02-22 23:42:38.130   594  4287 D audio_route: Apply path: low-latency-playback speaker                                                                       │
02-22 23:42:38.157  1217  1217 E BufferItemConsumer: [unnamed-1217-58] Failed to release buffer: Unknown error -1 (1)                                        │
02-22 23:42:38.187  4713  4713 D CordovaActivity: Started the activity.                                                                                      │
02-22 23:42:38.189  4713  4713 D CordovaActivity: Resumed the activity.                                                                                      │
02-22 23:42:38.190  4713  4713 I TSLocationManager: - onResume                                                                                               │
02-22 23:42:38.207  1217  1217 E BufferItemConsumer: [unnamed-1217-59] Failed to release buffer: Unknown error -1 (1)                                        │
02-22 23:42:38.212   594  4287 D audio_hw_primary: out_write: retry previous failed cal level set                                                            │
02-22 23:42:38.280  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.280  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.280  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/vendor.js: Line 62203 : [object Object]                                  │
02-22 23:42:38.281  4713  4713 I chromium: [INFO:CONSOLE(62203)] "[object Object]", source: http://localhost:8080/build/vendor.js (62203)                    │
02-22 23:42:38.341  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : App resumed.                                       │
02-22 23:42:38.341  4713  4713 I chromium: [INFO:CONSOLE(16234)] "App resumed.", source: http://localhost:8080/build/main.js (16234)                         │
02-22 23:42:38.403  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.403  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.448  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.449  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.471  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.471  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.480 23599  3595 I EventLogSendingHelper: Sending log events.                                                                                  │
02-22 23:42:38.489   432   597 E SurfaceFlinger: Failed to find layer (SnapshotStartingWindow for taskId=116#0) in layer parent (no-parent).                 │
02-22 23:42:38.515  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.515  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.610  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.610  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.632  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.632  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.645  1217  8563 I zygote64: Explicit concurrent copying GC freed 18800(932KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 7MB/14MB, pause│
02-22 23:42:38.658  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.658  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.680  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.680  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.707  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : [object Object]                                    │
02-22 23:42:38.708  4713  4713 I chromium: [INFO:CONSOLE(16234)] "[object Object]", source: http://localhost:8080/build/main.js (16234)                      │
02-22 23:42:38.735   594   751 D audio_hw_primary: disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback speaker                 │
02-22 23:42:38.741   594   751 D audio_hw_primary: disable_snd_device: snd_device(2: speaker)                                                                │
02-22 23:42:38.894  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : Heartbeat push completed in background mode.       │
02-22 23:42:38.894  4713  4713 I chromium: [INFO:CONSOLE(16234)] "Heartbeat push completed in background mode.", source: http://localhost:8080/build/main.js │
02-22 23:42:38.895  4713  4713 D SystemWebChromeClient: http://localhost:8080/build/main.js: Line 16234 : Completed background mode fetch.                   │
02-22 23:42:38.895  4713  4713 I chromium: [INFO:CONSOLE(16234)] "Completed background mode fetch.", source: http://localhost:8080/build/main.js (16234)     │
02-22 23:42:38.896  4713  4839 D TSBackgroundFetch: - finish                                                                                                 │
02-22 23:42:38.896  4713  4839 D TSBackgroundFetch: - jobFinished

Do you think this is just a case of data getting disabled in the background? Do you know if there is any way to confirm that it is what’s happening?

BackgroundFetch does not support a Promise API. There’s no possible way this could work (unless you’re using some sort of wrapper):

this.backgroundFetch.configure(config).then(this.fetchCallback.bind(this));

Don’t get cute, just follow the example in README:

BackgroundFetch.configure(() => {
  console.log('- Fetch received');
  BackgroundFetch.finish();
}, (error) => {
  console.log('- Fetch error');
}, {
        minimumFetchInterval: 15, // <-- default is 15
        stopOnTerminate: false   // <-- Android only        
    });