I am trying to generate a local notification with 2 actions. However, even though the notifications are popping up. I am not able to see the actions.
Is this because of something new in iOS 10
my viewcontroller,h has code:
-(void)createNotifications: (int)seconds{
UILocalNotification *local = [[UILocalNotification alloc]init];
local.fireDate = [[NSDate date]dateByAddingTimeInterval:seconds];
local.timeZone = nil;
local.alertBody = @"Alert body";
local.alertTitle = @"Alert Title";
local.alertAction = @"Okay";
local.soundName = UILocalNotificationDefaultSoundName;
local.applicationIconBadgeNumber = 4127;
local.category = @"MAIN_CATEGORY";
[[UIApplication sharedApplication] scheduleLocalNotification:local];
}
-(void)requestPermissionToNotify{
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc]init];
action.identifier = @"FLOAT_ACTION";
action.title = @"float";
action.activationMode = UIUserNotificationActivationModeBackground;
action.destructive = YES;
action.authenticationRequired = NO;
UIMutableUserNotificationAction *stingAction = [[UIMutableUserNotificationAction alloc]init];
stingAction.identifier = @"STING_ACTION";
stingAction.title = @"sting";
stingAction.activationMode = UIUserNotificationActivationModeForeground;
stingAction.destructive = NO;
stingAction.authenticationRequired = NO;
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc]init];
category.identifier = @"MAIN_CATEGORY";
NSSet *categories = [NSSet setWithObjects:category, nil];
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[category setActions:@[action,stingAction] forContext:UIUserNotificationActionContextDefault];
}
my appdelegate.m has callback handlers:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.applicationIconBadgeNumber = 0;
UILocalNotification *localnotif = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if(localnotif){
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Received while launch" message:localnotif.alertBody preferredStyle:UIAlertViewStyleDefault];
UIAlertAction *aa = [UIAlertAction actionWithTitle:@"okay" style:UIAlertViewStyleDefault handler:nil];
[alert addAction:aa];
dispatch_async(dispatch_get_main_queue(), ^{
[application.keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
});
}
return YES;
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
application.applicationIconBadgeNumber = 0;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Received while running" message:notification.alertBody preferredStyle:UIAlertViewStyleDefault];
UIAlertAction *aa = [UIAlertAction actionWithTitle:@"okay" style:UIAlertViewStyleDefault handler:nil];
[alert addAction:aa];
dispatch_async(dispatch_get_main_queue(), ^{
[application.keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
});
}
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Received while action" message:identifier preferredStyle:UIAlertViewStyleDefault];
UIAlertAction *aa = [UIAlertAction actionWithTitle:@"okay" style:UIAlertViewStyleDefault handler:nil];
[alert addAction:aa];
dispatch_async(dispatch_get_main_queue(), ^{
[application.keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
});
completionHandler();
}