Skip to content

Commit b293a83

Browse files
committed
Cherry pick sdk-274-push-ios13
1 parent 65ec956 commit b293a83

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Example/Tests/Classes/LPPushNotificationsHandlerTest.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,20 @@ - (void) test_receive_notification
105105

106106
//test when UNUserNotificationCenter.currentNotificationCenter.delegate is nil
107107
UNUserNotificationCenter.currentNotificationCenter.delegate = nil;
108-
[handler didReceiveRemoteNotification:userInfo
108+
109+
// Requires Leanplum Start
110+
// didReceiveRemoteNotification: UIApplicationState is Active -> calls handleNotification -> runs onContent on startIssued callback
111+
if (!Leanplum.hasStarted){
112+
XCTAssertTrue([LeanplumHelper start_production_test]);
113+
}
114+
115+
// Change messageId so it is not a duplicate notification
116+
NSDictionary* userInfo2 = @{
117+
@"_lpm": @"messageId_2",
118+
@"_lpx": @"test_action",
119+
@"aps" : @{@"alert": @"test"}};
120+
121+
[handler didReceiveRemoteNotification:userInfo2
109122
withAction:@"test_action"
110123
fetchCompletionHandler: ^(LeanplumUIBackgroundFetchResult result) {
111124
[applicationNotificationExpectation fulfill];

Leanplum-SDK/Classes/Notifications/Push/LPPushNotificationsHandler.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ - (void)handleNotification:(NSDictionary *)userInfo
230230
return;
231231
}
232232

233+
if ([self isDuplicateNotification:userInfo]) {
234+
return;
235+
}
236+
233237
void (^onContent)(void) = ^{
234238
if (completionHandler) {
235239
completionHandler(UIBackgroundFetchResultNewData);
@@ -266,11 +270,6 @@ - (void)maybePerformNotificationActions:(NSDictionary *)userInfo
266270
action:(NSString *)action
267271
active:(BOOL)active
268272
{
269-
// Do not perform the action if the app is in background
270-
if (UIApplication.sharedApplication.applicationState == UIApplicationStateBackground) {
271-
return;
272-
}
273-
274273
// Don't handle duplicate notifications.
275274
if ([self isDuplicateNotification:userInfo]) {
276275
return;

0 commit comments

Comments
 (0)