question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Timer] React Events not fired if the device is locked and screen turned off.

See original GitHub issue

If you have a delegate method that is fired every X seconds in the background when the device is locked. The delegate method is fired but the event is not. The following code

This log message Is triggered when the device is locked and screen is inactive.

NSLog(@"userUUID found %@", userUUID);

This event is triggered if the device is locked but the screen needs to be active.

[self.bridge.eventDispatcher sendDeviceEventWithName:@"nearByUserFound" body:@{@"userUUID":userUUID}];
//
//  ProximityManager.m
//  Proximity
//
//  Created by Adam Bulmer on 07/05/2015.
//  Copyright (c) 2015 Adam Bulmer All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ProximityManager.h"

@implementation ProximityManager

  @synthesize bridge = _bridge;

// MARK: React Native Bridge

  RCT_EXPORT_MODULE()

  RCT_EXPORT_METHOD(startAdvertising:(NSString *)appUUID
                    userUUID:(NSString*)userUUID) {
    self.proximity = [[Proximity alloc] initWithAppUUID:appUUID userUUID:userUUID delegate:self];
  }

  // MARK: ProximityDelegate Callbacks.

  - (void)nearbyUserFound:(NSString *)userUUID {
    NSLog(@"userUUID found %@", userUUID);
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"nearByUserFound" body:@{@"userUUID":userUUID}];
  }

@end

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:52 (33 by maintainers)

github_iconTop GitHub Comments

1reaction
yonahforstcommented, Feb 26, 2016

here’s my current hacky workaround:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

  [RCTPushNotificationManager didReceiveRemoteNotification:userInfo];

  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    completionHandler(UIBackgroundFetchResultNewData);
  });
}
0reactions
oneycommented, May 19, 2016

@nicklockwood agree with idea of pauseInBackground. We should pause animations in the background, but it should make developers decide to pause timers(setTimeout and setInterval) or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DeviceEventEmitter stops emitting events to application when ...
I wonder if this is related to "[Timer] React Events not fired if the device is locked and screen turned off"?
Read more >
Detecting iPhone lock and unlock w… - Apple Developer
Hi,. Is there a way to detect iPhone lock and unlock events from an iOS application when the app itself is in the...
Read more >
Screen Orientation - W3C
A screen can be in, or locked to, one of the following screen orientations : Any: The screen can be rotated by the...
Read more >
State and Lifecycle - React
If the Clock component is ever removed from the DOM, React calls the componentWillUnmount() lifecycle method so the timer is stopped. Using State...
Read more >
Why Javascript timer is unreliable, and how can you fix it
If you are a Javascript developer, at some point in your career, you must have used setTimeout or setInterval. They are extremely handy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found