IOS: notification actions - remove "open" in the options menu

I have notifications with some actions; now, if there is only one action for notification, it displays a “warning view” using the dismiss and options buttons. When I click on the options, I get "Open", "My Action" and "Close".

How can I achieve to avoid the options menu and get "Dismiss" and "My Action" from the very beginning?

I am talking about a warning that appears, for example. when you’re on the iPhone’s home screen and you have selected the “Alerts” notification style for “Unlock Alert Style”

I have a local push notification with only one action. Now I expect to receive a notification on the main screen with "Close" on the left and my specific action on the right. But instead, I get the following:

enter image description here

enter image description here

I would like to avoid the extra step of clicking "Options" and then get only one real option.

The code I'm using is:

 UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) { return; } localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:NOTIFICATION_DELAY]; localNotif.timeZone = [NSTimeZone defaultTimeZone]; localNotif.alertBody = text; localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; localNotif.category = ERROR_CATEGORY; [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 

registration for push notifications:

 UIMutableUserNotificationAction *callSupportAction = [self actionWithIdentifier:@"callSupportAction" title:NSLocalizedString(@"callSupportActionTitle", @"") background:YES destructive:NO authenticationRequired:NO]; UIMutableUserNotificationCategory *errorCategory = [self categoryWithIdentifier:ERROR_CATEGORY actions:@[callSupportAction]]; NSSet *categories = [NSSet setWithObjects:errorCategory, nil]; UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; - (UIMutableUserNotificationAction *)actionWithIdentifier:(NSString *)identifier title:(NSString *)title background:(BOOL)background destructive:(BOOL)destructive authenticationRequired:(BOOL)authenticationRequired { UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init]; action.identifier = identifier; action.title = title; action.activationMode = background ? UIUserNotificationActivationModeBackground : UIUserNotificationActivationModeForeground; action.destructive = destructive; action.authenticationRequired = authenticationRequired; return action; } - (UIMutableUserNotificationCategory *)categoryWithIdentifier:(NSString *)identifier actions:(NSArray *)actions { UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init]; category.identifier = identifier; if (actions.count > 2) { [category setActions:actions forContext:UIUserNotificationActionContextDefault]; [category setActions:[actions subarrayWithRange:NSMakeRange(0, 2)] forContext:UIUserNotificationActionContextMinimal]; } else { [category setActions:actions forContext:UIUserNotificationActionContextDefault]; } return category; } 
+5
source share

Source: https://habr.com/ru/post/1208498/


All Articles