6

I have registered for push and local notifications with two action buttons: action1 and action2. Upon receiving the notification, I can see both and can also take action depending on the action id. However, one of my use cases requires me to hide one or both the action buttons before I schedule local notification. Can I do that at run-time?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

In this method I am registering for notifications with 2 action buttons.

I see that depending on context we can define variable number of action buttons. However, context is predefined and not user defined.

Rajat
  • 10,977
  • 3
  • 38
  • 55
A_G
  • 2,260
  • 3
  • 23
  • 56
  • You can use UILocalNotification's property userInfo. Its NSDictionary object where you can set you value to hide option at time of schedule local notification. And fetch value at receiving the notification. base on this value you can hide/show your option. – Shreyank Nov 29 '16 at 06:33
  • @Astha Gupta Were you able to fix this? How did this work for you. I cant make it work. Thanks. – Missa Jan 23 '19 at 18:31

2 Answers2

1

Register user notification with multiple categories as you required like category1 with two actions, category2 with no action, category3 with only one action.

When creation of local notification, Use a defined category as you required. like this notificationName.category = @"Category_identifier";

Balaji
  • 144
  • 1
  • 6
0

For anyone looking for an answer to this in 2023 with Swift, this is what I did to get rid off all action buttons for a specific case at runtime. In NotificationService extension

var modifiedContent: UNMutableNotificationContent?

Then in didReceive function

guard let bestAttemptContent = modifiedContent else { return }
bestAttemptContent.categoryIdentifier = "" //Based on some condition
letsbondiway
  • 470
  • 3
  • 18