diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9f5a5ff..e95f7722a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +## 5.X.X (TBD) + +### Bug Fixes + +* Deregister notification observers and listeners before application termination [#301](https://github.com/bugsnag/bugsnag-cocoa/pull/301) + ## 5.16.2 (17 Jul 2018) ### Bug fixes diff --git a/Source/BugsnagNotifier.m b/Source/BugsnagNotifier.m index efcbc9c59..67cc4da40 100644 --- a/Source/BugsnagNotifier.m +++ b/Source/BugsnagNotifier.m @@ -308,12 +308,13 @@ - (void)start { onCrash:&BSSerializeDataCrashHandler]; [self setupConnectivityListener]; [self updateAutomaticBreadcrumbDetectionSettings]; - + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [self watchLifecycleEvents:center]; #if TARGET_OS_TV [self.details setValue:@"tvOS Bugsnag Notifier" forKey:BSGKeyName]; + [self addTerminationObserver:UIApplicationWillTerminateNotification]; #elif TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE [self.details setValue:@"iOS Bugsnag Notifier" forKey:BSGKeyName]; @@ -343,6 +344,8 @@ - (void)start { [self batteryChanged:nil]; [self orientationChanged:nil]; + [self addTerminationObserver:UIApplicationWillTerminateNotification]; + #elif TARGET_OS_MAC [self.details setValue:@"OSX Bugsnag Notifier" forKey:BSGKeyName]; @@ -355,6 +358,8 @@ - (void)start { selector:@selector(willEnterBackground:) name:NSApplicationDidResignActiveNotification object:nil]; + + [self addTerminationObserver:NSApplicationWillTerminateNotification]; #endif _started = YES; @@ -364,10 +369,31 @@ - (void)start { [self willEnterForeground:self]; } +- (void)addTerminationObserver:(NSString *)name { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(unsubscribeFromNotifications:) + name:name + object:nil]; +} + +/** + * Removes observers and listeners to prevent allocations when the app is terminated + */ +- (void)unsubscribeFromNotifications:(id)sender { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [self.networkReachable stopWatchingConnectivity]; + +#if TARGET_OS_TV || TARGET_OS_MAC +#elif TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [UIDevice currentDevice].batteryMonitoringEnabled = NO; + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; +#endif +} + - (void)watchLifecycleEvents:(NSNotificationCenter *)center { NSString *foregroundName; NSString *backgroundName; - + #if TARGET_OS_TV || TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE foregroundName = UIApplicationWillEnterForegroundNotification; backgroundName = UIApplicationWillEnterForegroundNotification; @@ -375,7 +401,7 @@ - (void)watchLifecycleEvents:(NSNotificationCenter *)center { foregroundName = NSApplicationWillBecomeActiveNotification; backgroundName = NSApplicationDidFinishLaunchingNotification; #endif - + [center addObserver:self selector:@selector(willEnterForeground:) name:foregroundName diff --git a/examples/objective-c-ios/Bugsnag Test App.xcodeproj/project.pbxproj b/examples/objective-c-ios/Bugsnag Test App.xcodeproj/project.pbxproj index a0da6f7f6..d41737ee0 100644 --- a/examples/objective-c-ios/Bugsnag Test App.xcodeproj/project.pbxproj +++ b/examples/objective-c-ios/Bugsnag Test App.xcodeproj/project.pbxproj @@ -276,8 +276,6 @@ F40B874316AA233500676BB2 /* Frameworks */, F40B874416AA233500676BB2 /* Resources */, 5142A2F8286744A694BDB5BA /* Upload Bugsnag dSYM */, - 765F7485E02A01DA5E42AC27 /* [CP] Embed Pods Frameworks */, - E142138E1656CA8499F1E0A3 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -409,36 +407,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 765F7485E02A01DA5E42AC27 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Bugsnag Test App/Pods-Bugsnag Test App-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - E142138E1656CA8499F1E0A3 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Bugsnag Test App/Pods-Bugsnag Test App-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/examples/objective-c-ios/Podfile.lock b/examples/objective-c-ios/Podfile.lock index c36191120..b4a6b6cb3 100644 --- a/examples/objective-c-ios/Podfile.lock +++ b/examples/objective-c-ios/Podfile.lock @@ -1,16 +1,16 @@ PODS: - - Bugsnag (5.15.3) + - Bugsnag (5.16.0) DEPENDENCIES: - Bugsnag (from `../..`) EXTERNAL SOURCES: Bugsnag: - :path: ../.. + :path: "../.." SPEC CHECKSUMS: - Bugsnag: 49464c6c2fb7a2eb5a66064586c64a6e23454c04 + Bugsnag: 47bcc70b43e3c616ec35d30c2ca94497b957199f PODFILE CHECKSUM: 4c48f26cc704429f747c4af7a40e026b20fdc83e -COCOAPODS: 1.4.0 +COCOAPODS: 1.5.0 diff --git a/examples/objective-c-osx/Podfile.lock b/examples/objective-c-osx/Podfile.lock index fb54123ee..d1677f02b 100644 --- a/examples/objective-c-osx/Podfile.lock +++ b/examples/objective-c-osx/Podfile.lock @@ -1,16 +1,16 @@ PODS: - - Bugsnag (5.14.1) + - Bugsnag (5.16.0) DEPENDENCIES: - Bugsnag (from `../..`) EXTERNAL SOURCES: Bugsnag: - :path: ../.. + :path: "../.." SPEC CHECKSUMS: - Bugsnag: bc62bf437f55cfae29a4c836f29f9e8b64af3457 + Bugsnag: 47bcc70b43e3c616ec35d30c2ca94497b957199f PODFILE CHECKSUM: df3de31179198c85e1d68a7930eb894bbeb22744 -COCOAPODS: 1.3.1 +COCOAPODS: 1.5.0 diff --git a/examples/objective-c-osx/objective-c-osx.xcodeproj/project.pbxproj b/examples/objective-c-osx/objective-c-osx.xcodeproj/project.pbxproj index 309898785..cd844b513 100644 --- a/examples/objective-c-osx/objective-c-osx.xcodeproj/project.pbxproj +++ b/examples/objective-c-osx/objective-c-osx.xcodeproj/project.pbxproj @@ -165,8 +165,6 @@ 93BE1CCC1B62CC360016380C /* Frameworks */, 93BE1CCD1B62CC360016380C /* Resources */, D24AA2BFC04EE1A1916426C8 /* Upload Bugsnag dSYM */, - 3B550964C9496E4003E11717 /* [CP] Embed Pods Frameworks */, - 2DB50B6F565C5C917EEF01B4 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -252,36 +250,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 2DB50B6F565C5C917EEF01B4 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-objective-c-osx/Pods-objective-c-osx-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 3B550964C9496E4003E11717 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-objective-c-osx/Pods-objective-c-osx-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; AF12CC88EC2DA5EF6D40C883 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/examples/swift-ios/bugsnag-example.xcodeproj/project.pbxproj b/examples/swift-ios/bugsnag-example.xcodeproj/project.pbxproj index f2b27c64f..fe47ce667 100644 --- a/examples/swift-ios/bugsnag-example.xcodeproj/project.pbxproj +++ b/examples/swift-ios/bugsnag-example.xcodeproj/project.pbxproj @@ -170,8 +170,6 @@ D175F4B51ACDBD81009AFFB7 /* Frameworks */, D175F4B61ACDBD81009AFFB7 /* Resources */, 9AFEEED933DC82BFDDB374F6 /* Upload Bugsnag dSYM */, - C54E80312CD2DFF73A2EEB6C /* [CP] Embed Pods Frameworks */, - AF034E316E834BBEE8E209A4 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -295,36 +293,6 @@ shellScript = "fork do\n Process.setsid\n STDIN.reopen(\"/dev/null\")\n STDOUT.reopen(\"/dev/null\", \"a\")\n STDERR.reopen(\"/dev/null\", \"a\")\n\n require 'shellwords'\n\n Dir[\"#{ENV[\"DWARF_DSYM_FOLDER_PATH\"]}/*/Contents/Resources/DWARF/*\"].each do |dsym|\n system(\"curl -F dsym=@#{Shellwords.escape(dsym)} -F projectRoot=#{Shellwords.escape(ENV[\"PROJECT_DIR\"])} https://upload.bugsnag.com/\")\n end\nend\n"; showEnvVarsInLog = 0; }; - AF034E316E834BBEE8E209A4 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-bugsnag-example/Pods-bugsnag-example-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - C54E80312CD2DFF73A2EEB6C /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-bugsnag-example/Pods-bugsnag-example-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */