diff --git a/Bugsnag/Helpers/BSGAppHangDetector.m b/Bugsnag/Helpers/BSGAppHangDetector.m index 2898de6cb..5a0eac529 100644 --- a/Bugsnag/Helpers/BSGAppHangDetector.m +++ b/Bugsnag/Helpers/BSGAppHangDetector.m @@ -11,6 +11,7 @@ #import #import +#import "BSG_KSCrashState.h" #import "BSG_KSMach.h" #import "BugsnagCollections.h" #import "BugsnagLogger.h" @@ -26,36 +27,11 @@ @interface BSGAppHangDetector () @property (nonatomic) CFRunLoopObserverRef observer; -@property (nonatomic) BOOL isInBackground; - @end @implementation BSGAppHangDetector -#if TARGET_OS_IOS - -- (instancetype)init { - if ((self = [super init])) { - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground) - name:UIApplicationDidEnterBackgroundNotification object:nil]; - - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationWillEnterForeground) - name:UIApplicationWillEnterForegroundNotification object:nil]; - } - return self; -} - -- (void)applicationDidEnterBackground { - self.isInBackground = YES; -} - -- (void)applicationWillEnterForeground { - self.isInBackground = NO; -} - -#endif - - (void)dealloc { if (_observer) { CFRunLoopRemoveObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes); @@ -89,7 +65,6 @@ - (void)startWithDelegate:(id)delegate { dispatch_queue_t backgroundQueue; __block dispatch_semaphore_t semaphore; __weak typeof(delegate) weakDelegate = delegate; - __weak typeof(self) weakSelf = self; backgroundQueue = dispatch_queue_create("com.bugsnag.app-hang-detector", DISPATCH_QUEUE_SERIAL); @@ -107,7 +82,7 @@ - (void)startWithDelegate:(id)delegate { dispatch_time_t timeout = dispatch_time(now, (int64_t)(threshold * NSEC_PER_SEC)); dispatch_after(after, backgroundQueue, ^{ if (dispatch_semaphore_wait(semaphore, timeout) != 0) { - if (weakSelf.isInBackground) { + if (!bsg_kscrashstate_currentState()->applicationIsInForeground) { bsg_log_debug(@"Ignoring app hang because app is in the background"); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); return; diff --git a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m index 219526aca..f5322766b 100644 --- a/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m +++ b/Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m @@ -176,10 +176,6 @@ - (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)dir free(crashReportPath); free(recrashReportPath); - if (!installedCrashTypes) { - return 0; - } - NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter]; #if BSG_HAS_UIKIT [nCenter addObserver:self diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ef325673..e1122ab2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Changelog ### Bug fixes +* Stop app hangs being reported if app is launched in the background. + [#1112](https://github.com/bugsnag/bugsnag-cocoa/pull/1112) + * Stop session being reported if app is launched in the background. [#1107](https://github.com/bugsnag/bugsnag-cocoa/pull/1107)