Setting dynamic button names in local notifications iOS8

I've followed examples here and elsewhere for setting local notifications to 1 or 2 buttons and they work fine. The examples are very good if you want canned buttons like Accept / Delete / etc, but I need to set the button names for what is happening in the application at the time. This is for the game and requires a universal engine. I need to be able to set the button names according to the needs at the time. I have two categories so I can make one button or two notification buttons. It seems like actions and categories need to be configured when registering for notification. The title in UIMutableUserNotificationCategory is displayed as read-only. I know it can be done. For example, the game "Spy Clock" can be played 90% of the time from notifications.

Are there any headers set when scheduling a notification? I passed in dictionaries with data that I need to process the response.

This is the AppDelegate side

NSString * const NotificationCategoryIdent1  = @"1BUTTON";
NSString * const NotificationCategoryIdent2  = @"2BUTTON";
NSString * const NotificationActionOneIdent = @"ACTION_ONE";
NSString * const NotificationActionTwoIdent = @"ACTION_TWO";

- (void)registerForNotification {

UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Button 1"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];

UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Button 2"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];

UIMutableUserNotificationCategory *actionCategory2;
actionCategory2 = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory2 setIdentifier:NotificationCategoryIdent2];
[actionCategory2 setActions:@[action1, action2]
                forContext:UIUserNotificationActionContextDefault];

UIMutableUserNotificationCategory *actionCategory1;
actionCategory1 = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory1 setIdentifier:NotificationCategoryIdent1];
[actionCategory1 setActions:@[action1]
                forContext:UIUserNotificationActionContextDefault];

NSSet *categories = [NSSet setWithObjects:actionCategory1, actionCategory2, nil];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                UIUserNotificationTypeSound|
                                UIUserNotificationTypeBadge);

UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
                                             categories:categories];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}

      

This is how I set up the notification in the view controller

UILocalNotification* localNotification2 = [[UILocalNotification alloc] init];
localNotification2.fireDate = [NSDate dateWithTimeIntervalSinceNow:30];
localNotification2.alertBody = @"Alert Body2";
localNotification2.timeZone = [NSTimeZone defaultTimeZone];
localNotification2.soundName = UILocalNotificationDefaultSoundName;
localNotification2.category = @"2BUTTON";
//localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];

      

+3
ios objective-c swift apple-push-notifications uilocalnotification


source to share


No one has answered this question yet

Check out similar questions:

445
How do I set the UIButton title to be left aligned?
366
Set UIBabton title UILabel font size programmatically
one hundred
How can I create local notifications on iOS?
87
Removing a specific local notification
eleven
Local and Push Notifications on IOS 9 and 10 using swift3
1
Removing MKMapView annotations causes leak
0
Dynamically set / deactivate activationMode for local notifications
0
Changing views keeps giving me an attempt to represent vc1 to vc whose view is not in the window hierarchy
0
View Json IOS passwords
0
How do I change the sound name of a local notification?



All Articles
Loading...
X
Show
Funny
Dev
Pics