From c5c41b449307d5f15fd2f7c47b9ecdaf61a5e492 Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Tue, 28 May 2024 10:55:00 -0500 Subject: [PATCH] Fix setting urlDelegate on Braze instance --- Sources/mParticle-Appboy/MPKitAppboy.m | 12 ++++++------ mParticle_AppboyTests/mParticle_AppboyTests.m | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/mParticle-Appboy/MPKitAppboy.m b/Sources/mParticle-Appboy/MPKitAppboy.m index 9deec34..8205a8b 100644 --- a/Sources/mParticle-Appboy/MPKitAppboy.m +++ b/Sources/mParticle-Appboy/MPKitAppboy.m @@ -48,10 +48,10 @@ static NSString *const impressionKey = @"impressions"; #if TARGET_OS_IOS -__weak static id inAppMessageControllerDelegate = nil; +static id inAppMessageControllerDelegate = nil; static BOOL shouldDisableNotificationHandling = NO; #endif -__weak static id urlDelegate = nil; +static id urlDelegate = nil; static Braze *brazeInstance = nil; static id brazeLocationProvider = nil; static NSSet *brazeTrackingPropertyAllowList; @@ -367,6 +367,10 @@ - (void)start { } [self->appboyInstance setAdTrackingEnabled:[self isAppTrackingEnabled]]; + if ([MPKitAppboy urlDelegate]) { + self->appboyInstance.delegate = [MPKitAppboy urlDelegate]; + } + #if TARGET_OS_IOS BrazeInAppMessageUI *inAppMessageUI = [[BrazeInAppMessageUI alloc] init]; inAppMessageUI.delegate = [MPKitAppboy inAppMessageControllerDelegate]; @@ -447,10 +451,6 @@ - (void)start { } #endif - if ([MPKitAppboy urlDelegate]) { - optionsDictionary[ABKURLDelegateKey] = (NSObject *)[MPKitAppboy urlDelegate]; - } - return optionsDictionary; } diff --git a/mParticle_AppboyTests/mParticle_AppboyTests.m b/mParticle_AppboyTests/mParticle_AppboyTests.m index 2a1a65b..1553a9f 100644 --- a/mParticle_AppboyTests/mParticle_AppboyTests.m +++ b/mParticle_AppboyTests/mParticle_AppboyTests.m @@ -31,6 +31,7 @@ - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. [MPKitAppboy setBrazeInstance:nil]; + [MPKitAppboy setURLDelegate:nil]; } - (void)tearDown { @@ -261,7 +262,7 @@ - (void)testSetMessageDelegate { [self waitForExpectationsWithTimeout:1 handler:nil]; } -- (void)testWeakMessageDelegate { +- (void)testStrongMessageDelegate { id delegate = (id)[NSObject new]; [MPKitAppboy setInAppMessageControllerDelegate:delegate]; @@ -271,7 +272,7 @@ - (void)testWeakMessageDelegate { XCTestExpectation *expectation = [self expectationWithDescription:@"async work"]; dispatch_async(dispatch_get_main_queue(), ^{ - XCTAssertNil([MPKitAppboy inAppMessageControllerDelegate]); + XCTAssertNotNil([MPKitAppboy inAppMessageControllerDelegate]); [expectation fulfill]; });