Can't make UIUserNotificationActionBehaviorTextInput work - ios

UIMutableUserNotificationAction *answer;
answer = [[UIMutableUserNotificationAction alloc] init];
[answer setActivationMode:UIUserNotificationActivationModeBackground];
[answer setTitle:#"Answer"];
[answer setIdentifier:#"Answer"];
[answer setDestructive:NO];
[answer setAuthenticationRequired:NO];
[answer setBehavior:UIUserNotificationActionBehaviorTextInput];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:#[answer]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
This is how I set up my "Reply" action. As you can see, I specified the desired behavior. However, when I receive some notification, I pull it down and see this "Answer" button. What's the problem? Where is the textfield?

Related

Local notification override Remote notification (Actionable notification) setting in iOS 9?

I used following code for remote notification
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:#"REJECT"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:#"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:#[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
//Right, that is the point
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
//register to receive notifications
[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
This works fine show's correct (Accept/Reject buttons). For some condition i want to wake up app to Foreground so i am using following local notification code in
(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void
(^)())completionHandler method.
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeForeground];
[action1 setTitle:#"LAUNCH"];
[action1 setIdentifier:#"OPEN_ACTION"];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:#"LOCAL_NOTIFICATIOn"];
[actionCategory setActions:#[action1]
forContext:UIUserNotificationActionContextDefault];
[actionCategory setActions:#[action1]
forContext:UIUserNotificationActionContextMinimal];
NSSet *categories1 = [NSSet setWithObject:actionCategory];
UIUserNotificationSettings *settings2 = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories1];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings2];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertTitle= #"Security settings enabled,";
localNotification.alertBody = #"tap the Launch button to start the application";
localNotification.category = #"LOCAL_NOTIFICATIOn";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Problem: First time Remote notification show's Accept/Reject button correctly but after registering Local notification Remote notification doesn't shows action buttons(Accept/Reject). I can't seen buttons in alerts?
Your remote notification setting overridden by local notification setting.
// Registering UIUserNotificationSettings more than once results in previous settings being overwritten.
- (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
comment this code:
[[UIApplication sharedApplication] registerUserNotificationSettings:settings2];

iOS Interactive UILocalNotifications

I am trying to implement Interactive UILocalNotifications.
Following is my code. I am unable to get 3 Action Buttons of receiving Notification.
UIMutableUserNotificationAction *nAction1 = [[UIMutableUserNotificationAction alloc] init];
nAction1.identifier = #"Present";
nAction1.title = #"Present";
nAction1.activationMode = UIUserNotificationActivationModeBackground;
nAction1.destructive = NO;
nAction1.authenticationRequired = YES;
UIMutableUserNotificationAction *nAction2 = [[UIMutableUserNotificationAction alloc] init];
nAction2.identifier = #"Late";
nAction2.title = #"Late";
nAction2.activationMode = UIUserNotificationActivationModeBackground;
nAction2.destructive = NO;
nAction2.authenticationRequired = YES;
UIMutableUserNotificationAction *nAction3 = [[UIMutableUserNotificationAction alloc] init];
nAction3.identifier = #"Absent";
nAction3.title = #"Absent";
nAction3.activationMode = UIUserNotificationActivationModeBackground;
nAction3.destructive = YES;
nAction3.authenticationRequired = YES;
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = #"Attendance";
[notificationCategory setActions:#[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:#[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];
UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.alertBody = #"Testing";
localNotification.category = #"Attendance";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[notificationCategory setActions:#[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:#[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];
It seems that you are overriding the same context with just 2 buttons I guess that the correct should be:
[notificationCategory setActions:#[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:#[nAction3, nAction1] forContext:UIUserNotificationActionContextMinimal];

ios 8 interactive notifications not showing actions

This is my code to register Interactive Notifications for ios8 :
+ (void)registerInteractiveNotifications
{
UIMutableUserNotificationCategory *corideInviteCategory = [self corideInviteCategory];
UIMutableUserNotificationCategory *riderInviteCategory = [self riderInviteCategory];
NSSet *categories = [NSSet setWithObjects:corideInviteCategory, riderInviteCategory, nil];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
+ (UIMutableUserNotificationCategory *)riderInviteCategory
{
UIMutableUserNotificationAction *accept;
accept = [[UIMutableUserNotificationAction alloc] init];
[accept setActivationMode:UIUserNotificationActivationModeForeground];
[accept setTitle:#"Accept"];
[accept setIdentifier:RiderInviteAccept];
[accept setDestructive:NO];
[accept setAuthenticationRequired:NO];
UIMutableUserNotificationAction *decline;
decline = [[UIMutableUserNotificationAction alloc] init];
[decline setActivationMode:UIUserNotificationActivationModeForeground];
[decline setTitle:#"Decline"];
[decline setIdentifier:RiderInviteDecline];
[decline setDestructive:YES];
[decline setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:RiderInviteCategory];
[actionCategory setActions:#[decline, accept]
forContext:UIUserNotificationActionContextDefault];
[actionCategory setActions:#[decline, accept] forContext:UIUserNotificationActionContextMinimal];
return actionCategory;
}
+ (UIMutableUserNotificationCategory *)corideInviteCategory
{
UIMutableUserNotificationAction *accept;
accept = [[UIMutableUserNotificationAction alloc] init];
[accept setActivationMode:UIUserNotificationActivationModeForeground];
[accept setTitle:#"Accept"];
[accept setIdentifier:CorideInviteAccept];
[accept setDestructive:NO];
[accept setAuthenticationRequired:NO];
UIMutableUserNotificationAction *decline;
decline = [[UIMutableUserNotificationAction alloc] init];
[decline setActivationMode:UIUserNotificationActivationModeForeground];
[decline setTitle:#"Decline"];
[decline setIdentifier:CorideInviteDecline];
[decline setDestructive:YES];
[decline setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:CorideInviteCategory];
[actionCategory setActions:#[decline, accept]
forContext:UIUserNotificationActionContextDefault];
[actionCategory setActions:#[decline, accept] forContext:UIUserNotificationActionContextMinimal];
return actionCategory;
}
What happens is : when i delete the app and install again, the 2 action buttons (when I pull down the notification banner, or swipe left in notification center) appears. But after a while ( i'm not really sure what cause it ), they stop appearing although i keep sending the same notification. This is my notification content:
{"aps":{"alert":"test","category":"coride_invite"},"journey_id":100}
Can anyone shed some light please ? Thanks
Check for the following in you code if it is anywhere else as well:
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
Since, UIUserNotificationSettings is singleton, whenever you call this, it overwrites the old settings. So if new settings is registered without any buttons it will not show any buttons.
Better way of registering new setting is explained here:
Interactive push notifications - Hide/Show buttons

Action Buttons won't show in Notification

I'm trying to add iOS8 Action Buttons to my already working notifications. But they won't show up. It's just a normal notification without buttons.
//Action
UIMutableUserNotificationAction* loginAction = [[UIMutableUserNotificationAction alloc] init];
loginAction.identifier = #"loginAction"; //ID string to be passed back to your app when you handle the action
loginAction.title = #"login";
loginAction.activationMode = UIUserNotificationActivationModeForeground;
loginAction.destructive = NO;
loginAction.authenticationRequired = YES;
//Category
UIMutableUserNotificationCategory* loginCategory = [[UIMutableUserNotificationCategory alloc] init];
loginCategory.identifier = #"loginCategory"; //ID to include in your push payload
[loginCategory setActions:[NSArray arrayWithObjects:loginAction, nil] forContext:UIUserNotificationActionContextDefault];
//Register Settings and Notification
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:[NSSet setWithObject:loginCategory]]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
Using this code will have the same effect as setting the categories parameter to nil.
The payload looks like this:
'{"aps":{"alert":{"body":"text"},"category":"loginCategory"}}'
I just added the category key to the payload.
What am i missing?
Here is a very simple example, in Objective-C, of how to register a notification that has 2 actions.
NSString * const NotificationCategoryIdent = #"ACTIONABLE";
NSString * const NotificationActionOneIdent = #"ACTION_ONE";
NSString * const NotificationActionTwoIdent = #"ACTION_TWO";
- (void)registerForNotification {
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:#"Action 1"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:#"Action 2"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:#[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
To send this type of notification simply add the category to the payload.
"aps" : {
"alert" : "Pull down to interact.",
"category" : "ACTIONABLE"
}
These methods will get called, in the background, when the user selects an action from your push notification.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler {
if ([identifier isEqualToString:NotificationActionOneIdent]) {
NSLog(#"You chose action 1.");
}
else if ([identifier isEqualToString:NotificationActionTwoIdent]) {
NSLog(#"You chose action 2.");
}
if (completionHandler) {
completionHandler();
}
}
Hope this helps...cheers !!!

Register for Remote AND Local Notifications

In my app I want to support both - Remote Notifications and Local Notifications. The Remote Notification should have two actions that let the user interact with it in Notification Center.
Currently I have this code to register for notifications. My question is do I have to call register for local notifications separately or are local notifications already included in this registration process.
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIMutableUserNotificationAction *actionCancel = [[UIMutableUserNotificationAction alloc] init];
[actionCancel setActivationMode:UIUserNotificationActivationModeBackground];
[actionCancel setTitle:#"Cancel"];
[actionCancel setIdentifier:NotificationActionOneIdent];
[actionCancel setDestructive:NO];
[actionCancel setAuthenticationRequired:NO];
UIMutableUserNotificationAction *actionOk = [[UIMutableUserNotificationAction alloc] init];
[actionOk setActivationMode:UIUserNotificationActivationModeBackground];
[actionOk setTitle:#"Ok"];
[actionOk setIdentifier:NotificationActionTwoIdent];
[actionOk setDestructive:NO];
[actionOk setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:#[actionCancel, actionOk]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
locals are included when you registerUserNotificationSettings so your code is fine

Resources