问题
I'm trying to create an app that delivers local notifications as an Alert, not a Banner. But looks like banner is the default and I can't find a way to change it on my code. I can change it on the app notification settings and it works perfectly, but I want that configuration to be default.
This is the code I use to ask the user for permission to send notifications:
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
(By the way, does someone know why I can't set icon badge with this code?)
And this is the code I use to create the Local Notification:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:segundosTotal];
localNotification.alertBody = timer.nome;
localNotification.soundName = @"Default-28-sec-192kbps.mp3";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
With this code I get the default Banner notification, how can I change that to the Alert one?
回答1:
I don't believe there is any way to programmatically force the system to display your notification as an alert rather than as a banner. Looking over the documentation for UILocalNotification and for UIUserNotificationSettings, I don't see anything that would allow you to specify that you want an alert instead of a banner.
It's up to the user to adjust their notification settings for your app - I would leave it to them to decide how they want to receive notifications.
来源:https://stackoverflow.com/questions/29449539/how-to-change-notification-type-from-banner-to-alert-in-ios8