diff options
author | Julian Rex <julian.rex@mapbox.com> | 2019-03-25 09:19:40 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2019-04-16 11:38:41 -0400 |
commit | 4a0ab7a90871376806014a4d4500b6462f436acf (patch) | |
tree | 8926f27dc350a0cae6b23159ff9034a15e3ccd9e | |
parent | 700dc4decfdafb0978832891196b4b0b1cb934c6 (diff) | |
download | qtlocation-mapboxgl-4a0ab7a90871376806014a4d4500b6462f436acf.tar.gz |
[ios] Defensive code for application delegate handling.
-rw-r--r-- | platform/ios/Integration Tests/MGLBackgroundIntegrationTest.m | 2 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLMockApplication.m | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/platform/ios/Integration Tests/MGLBackgroundIntegrationTest.m b/platform/ios/Integration Tests/MGLBackgroundIntegrationTest.m index cea52740d2..b4d3eed4e8 100644 --- a/platform/ios/Integration Tests/MGLBackgroundIntegrationTest.m +++ b/platform/ios/Integration Tests/MGLBackgroundIntegrationTest.m @@ -53,6 +53,7 @@ typedef void (^MGLNotificationBlock)(NSNotification*); // Setup MGLMapView to use our new mocked application // Change notification handling here. self.oldApplication = self.mapView.application; + self.mockApplication.delegate = self.oldApplication.delegate; self.mapView.application = self.mockApplication; } @@ -63,6 +64,7 @@ typedef void (^MGLNotificationBlock)(NSNotification*); // Swap back self.mapView.application = self.oldApplication; self.oldApplication = nil; + self.mockApplication.delegate = nil; self.mockApplication = nil; [super tearDown]; diff --git a/platform/ios/Integration Tests/MGLMockApplication.m b/platform/ios/Integration Tests/MGLMockApplication.m index 3654e3ed54..06a8e173f1 100644 --- a/platform/ios/Integration Tests/MGLMockApplication.m +++ b/platform/ios/Integration Tests/MGLMockApplication.m @@ -8,6 +8,12 @@ @implementation MGLMockApplication +- (void)dealloc { + if (_delegate) { + CFRelease((CFTypeRef)_delegate); + } +} + - (instancetype)init { if ((self = [super init])) { _applicationState = UIApplicationStateActive; @@ -32,6 +38,21 @@ self.applicationState = UIApplicationStateActive; } +- (void)setDelegate:(id<UIApplicationDelegate>)delegate { + // Property is `assign`, but we want to retain + if (_delegate != delegate) { + if (_delegate) { + CFRelease((CFTypeRef)_delegate); + } + + _delegate = delegate; + + if (_delegate) { + CFRetain((CFTypeRef)_delegate); + } + } +} + - (BOOL)openURL:(NSURL*)url { TRACE(); return NO; |