Skip to content

Commit

Permalink
Merge 5007caa into dd0557f
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Nov 2, 2023
2 parents dd0557f + 5007caa commit acd1676
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Stop sending empty thread names (#3361)
- Work around edge case with a thread info kernel call sometimes returning invalid data, leading to a crash (#3364)
- Reading applicationState in the background (#3372)

## 8.14.2

Expand Down
41 changes: 39 additions & 2 deletions Sources/Sentry/SentryUIApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@

# import <UIKit/UIKit.h>

@implementation SentryUIApplication
@implementation SentryUIApplication {
UIApplicationState appState;
}

- (instancetype)init
{
if (self = [super init]) {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(didEnterBackground)
name:UIApplicationDidEnterBackgroundNotification
object:nil];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(didBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// We store the application state when the app is initialized
// and we keep track of its changes by the notifications
// this way we avoid calling sharedApplication in a background thread
appState = self.sharedApplication.applicationState;
}
return self;
}

- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
}

- (UIApplication *)sharedApplication
{
Expand Down Expand Up @@ -58,7 +85,17 @@ - (UIApplication *)sharedApplication

- (UIApplicationState)applicationState
{
return self.sharedApplication.applicationState;
return appState;
}

- (void)didEnterBackground
{
appState = UIApplicationStateBackground;
}

- (void)didBecomeActive
{
appState = UIApplicationStateActive;
}

@end
Expand Down

0 comments on commit acd1676

Please sign in to comment.