How to change notification type from Banner to Alert in iOS8?

扶醉桌前 提交于 2019-12-18 09:26:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!