Why Ng-Idle not working on iOS when app is in background mode for ionic 4?

Hi Guys!

I am using Ng-Idle for session time-out functionality. it’s working fine in android for both foreground and background mode of the app but in iOS 13 it is only working when the app is in foreground mode but if I run the app in background mode its not working code is written inside the idle.onTimeout is not working.

If anyone knows how to solve it or about something that can help with that, I’ll be glad to read about it.

Ionic:

   Ionic CLI                     : 5.2.7
   Ionic Framework               : @ionic/angular 4.11.5
   @angular-devkit/build-angular : 0.803.19
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.3.19
   @ionic/angular-toolkit        : 2.1.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 20 other plugins)

Utility:

   cordova-res : 0.8.1
   native-run  : 0.2.9

System:

   NodeJS : v10.15.3 
   npm    : 6.4.1
   OS     : Windows 10
setIdle() {
      this.idle.setIdle(5); 
      this.idle.setTimeout(5);
      this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
      this.idle.onTimeout.subscribe(() => {
        console.log("Idle Timed Out");
      });
      this.idle.watch();
  }

Hi, I too facing same problem. Did u find solution to this ?

Hi, still not found any solution for this.

I’m using the latest ng-idle (8.0.0-beta.4) the behavior is quite uncertain. Though most of time it doesn’t track the time, sometimes it tracks with a delay. Say I want to track 60 seconds and app goes to background and comes to foreground at 60 sec, then it would be tracked around 80 second. So it is working with some error. What about your case ?

Hi,

By removing two lines from one of the app background mode plugin file APPBackgroundMode.m in Xcode. Now it’s working fine for me.

It may be line number : 265 & 266:

 [obj setValue:[NSNumber numberWithBool:YES]
        forKey:[APPBackgroundMode wkProperty]];