Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...