Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Libraries/AppStateIOS/AppStateIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ var _eventHandlers = {
* - `active` - The app is running in the foreground
* - `background` - The app is running in the background. The user is either
* in another app or on the home screen
* - `inactive` - This is a transition state that currently never happens for
* typical React Native apps.
* - `inactive` - This is a state that occurs when transitioning between
* foreground & background, and during periods of inactivity such as
* entering the Multitasking view or in the event of an incoming call
*
* For more information, see
* [Apple's documentation](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html)
Expand Down
23 changes: 17 additions & 6 deletions React/Modules/RCTAppState.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
dispatch_once(&onceToken, ^{
states = @{
@(UIApplicationStateActive): @"active",
@(UIApplicationStateBackground): @"background",
@(UIApplicationStateInactive): @"inactive"
@(UIApplicationStateBackground): @"background"
};
});

Expand Down Expand Up @@ -53,9 +52,12 @@ - (void)setBridge:(RCTBridge *)bridge

for (NSString *name in @[UIApplicationDidBecomeActiveNotification,
UIApplicationDidEnterBackgroundNotification,
UIApplicationDidFinishLaunchingNotification]) {
UIApplicationDidFinishLaunchingNotification,
UIApplicationWillResignActiveNotification,
UIApplicationWillEnterForegroundNotification]) {

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAppStateDidChange)
selector:@selector(handleAppStateDidChange:)
name:name
object:nil];
}
Expand All @@ -79,9 +81,18 @@ - (void)dealloc

#pragma mark - App Notification Methods

- (void)handleAppStateDidChange
- (void)handleAppStateDidChange:(NSNotification *)notification
{
NSString *newState = RCTCurrentAppBackgroundState();
NSString *newState;

if ([notification.name isEqualToString:UIApplicationWillResignActiveNotification]) {
newState = @"inactive";
} else if ([notification.name isEqualToString:UIApplicationWillEnterForegroundNotification]) {
newState = @"active";
} else {
newState = RCTCurrentAppBackgroundState();
}

if (![newState isEqualToString:_lastKnownState]) {
_lastKnownState = newState;
[_bridge.eventDispatcher sendDeviceEventWithName:@"appStateDidChange"
Expand Down