@@ -1186,6 +1186,42 @@ - (void)testNotificationOpenFromButtonPressWithNewformat {
11861186 XCTAssertEqual (OneSignalClientOverrider.networkRequestCount , 3 );
11871187}
11881188
1189+ // Testing receiving a notification while the app is in the foreground but inactive.
1190+ // Received should be called but opened should not be called
1191+ - (void )testNotificationReceivedWhileAppInactive {
1192+ __block BOOL openedWasFired = false ;
1193+ __block BOOL receivedWasFired = false ;
1194+
1195+ [OneSignal initWithLaunchOptions: nil appId: @" b2f7f966-d8cc-11e4-bed1-df8f05be55ba" handleNotificationReceived: ^(OSNotification *notification) {
1196+ receivedWasFired = true ;
1197+ } handleNotificationAction: ^(OSNotificationOpenedResult *result) {
1198+ openedWasFired = true ;
1199+ } settings: nil ];
1200+
1201+ [UnitTestCommonMethods runBackgroundThreads ];
1202+ UIApplicationOverrider.currentUIApplicationState = UIApplicationStateInactive;
1203+
1204+ id userInfo = @{@" aps" : @{
1205+ @" mutable-content" : @1 ,
1206+ @" alert" : @" Message Body"
1207+ },
1208+ @" os_data" : @{
1209+ @" i" : @" b2f7f966-d8cc-11e4-bed1-df8f05be55ba" ,
1210+ @" buttons" : @[@{@" i" : @" id1" , @" n" : @" text1" }],
1211+ }};
1212+
1213+ UNNotification *notif = [UnitTestCommonMethods createBasiciOSNotificationWithPayload: userInfo];
1214+
1215+ UNUserNotificationCenter *notifCenter = [UNUserNotificationCenter currentNotificationCenter ];
1216+ id notifCenterDelegate = notifCenter.delegate ;
1217+
1218+ [notifCenterDelegate userNotificationCenter: notifCenter willPresentNotification: notif withCompletionHandler: ^(UNNotificationPresentationOptions options) {}];
1219+
1220+
1221+ XCTAssertEqual (openedWasFired, false );
1222+ XCTAssertEqual (receivedWasFired, true );
1223+ }
1224+
11891225// Testing iOS 10 - 2.4.0+ button fromat - with os_data aps payload format
11901226- (void )notificationAlertButtonsDisplayWithFormat : (NSDictionary *)userInfo {
11911227 [[OneSignalDialogController sharedInstance ] clearQueue ];
0 commit comments