Skip to content

Commit 73e75fa

Browse files
Aligned iOS local fg notification behavior with Android (localNotificationReceived only triigers when tapped, not when shown)
1 parent b75086f commit 73e75fa

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Ports/iOSPort/nativeSources/CodenameOne_GLAppDelegate.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
394394
{
395395
CN1Log(@"Received local notification while running: %@", notification);
396396

397-
NSString* alertValue = [notification.request.content.userInfo valueForKey:@"__ios_id__"];
398-
com_codename1_impl_ios_IOSImplementation_localNotificationReceived___java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG alertValue));
399397
if (completionHandler != nil) {
400398
if ([notification.request.content.userInfo valueForKey:@"foreground"] != NULL) {
401399
completionHandler(UNNotificationPresentationOptionAlert);
@@ -419,8 +417,20 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
419417

420418

421419
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
420+
#ifdef CN1_INCLUDE_NOTIFICATIONS
421+
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
422+
if(state == UIApplicationStateActive)
423+
{
424+
if( [response.notification.request.content.userInfo valueForKey:@"__ios_id__"] != NULL)
425+
{
426+
CN1Log(@"Received local notification while running: %@", response.notification);
422427

423-
428+
NSString* alertValue = [response.notification.request.content.userInfo valueForKey:@"__ios_id__"];
429+
if ([response.notification.request.content.userInfo valueForKey:@"foreground"] != NULL)
430+
com_codename1_impl_ios_IOSImplementation_localNotificationReceived___java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG alertValue));
431+
}
432+
}
433+
#endif
424434
#ifdef INCLUDE_CN1_PUSH
425435
NSLog( @"Handle push from background or closed" );
426436
// if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background
@@ -589,11 +599,6 @@ -(void)application:(UIApplication*)application didChangeStatusBarFrame:(CGRect)o
589599

590600
- (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification {
591601
CN1Log(@"Received local notification while running: %@", notification);
592-
if( [notification.userInfo valueForKey:@"__ios_id__"] != NULL)
593-
{
594-
NSString* alertValue = [notification.userInfo valueForKey:@"__ios_id__"];
595-
com_codename1_impl_ios_IOSImplementation_localNotificationReceived___java_lang_String(CN1_THREAD_GET_STATE_PASS_ARG fromNSString(CN1_THREAD_GET_STATE_PASS_ARG alertValue));
596-
}
597602
}
598603

599604
#ifndef CN1_USE_ARC

0 commit comments

Comments
 (0)