Skip to content

Commit bebb504

Browse files
fix: MPAppNotificationHandler webpageURL issue (#353)
1 parent a0422bc commit bebb504

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

UnitTests/MPAppNotificationHandlerTests.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,19 @@ - (void)testOpenURLOptions {
8484
[appNotificationHandler openURL:url options:options];
8585
}
8686

87+
- (void)testContinueUserActivityNoCrash {
88+
MPAppNotificationHandler *appNotificationHandler = [MParticle sharedInstance].appNotificationHandler;
89+
90+
NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:@"test"];
91+
userActivity.webpageURL = [[NSURL alloc] initWithString:@"http://mparticle.com"];
92+
[appNotificationHandler continueUserActivity:userActivity restorationHandler:^(NSArray<id<UIUserActivityRestoring>> *restorationHandler){}];
93+
}
94+
95+
- (void)testContinueUserActivityWithNilURLNoCrash {
96+
MPAppNotificationHandler *appNotificationHandler = [MParticle sharedInstance].appNotificationHandler;
97+
98+
NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:@"test"];
99+
[appNotificationHandler continueUserActivity:userActivity restorationHandler:^(NSArray<id<UIUserActivityRestoring>> *restorationHandler){}];
100+
}
101+
87102
@end

mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ - (BOOL)continueUserActivity:(nonnull NSUserActivity *)userActivity restorationH
281281
return NO;
282282
}
283283

284-
stateMachine.launchInfo = [[MPLaunchInfo alloc] initWithURL:userActivity.webpageURL options:nil];
284+
if (userActivity.webpageURL != nil) {
285+
stateMachine.launchInfo = [[MPLaunchInfo alloc] initWithURL:userActivity.webpageURL options:nil];
286+
} else {
287+
NSURL *defaultURL = [[NSURL alloc] initWithString:@""];
288+
stateMachine.launchInfo = [[MPLaunchInfo alloc] initWithURL:defaultURL options:nil];
289+
}
285290

286291
SEL continueUserActivitySelector = @selector(continueUserActivity:restorationHandler:);
287292

0 commit comments

Comments
 (0)