Does your CBListener stops listening after your device is unlocked



We’ve been using the CouchBase Lite REST listener for iOS (CBListener) in our React Native project (via react-native-couchbase-lite)

One weird thing that we’ve noticed is that if the app is sent to the background (example home button pressed) and brought back to the foreground everything seems ok. But if the device is locked (even with our app in the foreground) and then unlocked the CBListener is no longer listening and requests start failing.

My questions:

  • Is this expected behaviour?
  • Does anybody else share this experience?
  • Are we doing something wrong?

To work around it this issue we set the listener as a property of the delegate and we are starting and stopping the listener as the app enters and exits the foreground.

- (void)applicationDidEnterBackground:(UIApplication *)application {
  [self.cbListener stop];

- (void)applicationWillEnterForeground:(UIApplication *)application {
  NSError *anyError;
  if (![self.cbListener start:&anyError]) {
    NSLog(@"applicationWillEnterForeground: cbListener start failed with error: %@", anyError);
  • Is this a sensical solution?
  • Could this cause havoc to a replication in progress?

It seems ok for now, but I could imagine problems if we try and doing anything (such as syncing) in the background.


Yes, it’s expected. iOS does not allow apps to run listener sockets when they’re not active; in practice the socket gets killed when the device locks, and sometimes when the app has been in the background long enough.

Your workaround is exactly what I’d recommend.