Set default iOS local notification style for application
Asked Answered
R

6

38

Starting with iOS 5, there are two notification styles: banner and alert (the "old" style). A user can set which style to use for each application in the settings. However, the default now seems to be that notifications are displayed banner style.

I'm using local notifications for reminders about events that will happen "now". A banner disappears shortly after it appeared (and it's not obvious enough that one can tap it), so for these notifications it would be desirable to have the alert style notifications as those stay on screen until the user decided on an action (ignore or go to app).

Is there a way either through code or for example Info.plist entries to tell iOS that the alert style notifications should be used by default (as long as the user hasn't configured something else)?

Update: The absence of information/documentation is not enough for me to have this settled. I want either something like a forum/blog post from someone with authority (Apple employee or someone along the lines of Erica Sadun) saying it's not possible, or if it is possible then I want the solution. A workaround like "ask the user to change the setting" isn't good enough either.

Rugg answered 22/11, 2011 at 15:34 Comment(6)
have you tried using the method on page 53-54 of this doc? developer.apple.com/library/ios/documentation/iphone/conceptual/…Boeschen
@DanZimm: The problem is not scheduling local notifications. The problem is to tell iOS to use the alert style to display them by default. The documentation you've cited doesn't tell anything about that.Rugg
gotcha - i thought maybe the way a uilocalnotification is created and configured might affect its appearance, my bad :PBoeschen
have you got the correct answer to this? we are also trying to find a solution to this.Wacker
@IBG: Since someone else filed a radar for this I didn't bother. So no, I don't have an answer to this yet.Rugg
Any news now that we are in 2014 with iOS7? I can't believe how they don't let you set a default style in a plist, which the user can later change from the settings. So frustrating!Eckenrode
W
20

I would like to add something, since I've opened a TSI and somehow I asked about this and have been answered. From Quinn "The Eskimo!":

"This depends on you mean. You have some control over how the notification appears based on how you set the UILocalNotification properties (things like alertBody, soundName, and so on). However, if you're asking about the way in which those properties are interpreted (the things the user can customise in Settings > Notifications), those are user preferences and not exposed via any API."

Wacker answered 4/2, 2012 at 1:3 Comment(3)
Its The real answer to the question, for further help , here is what I observedAnglonorman
alert style depends upon the 3 properties i.e alertBody, alertAction and alertTitle, if you only provide alert body then style would be banner, if none of these is provided then it would be none else it would be alertAnglonorman
@JProgrammer I've provided all three, but it's still banner. What am I doing wrong?Chassidychassin
C
16

I have an alarm app for which I also need this functionality. Under iOS5 if the user is using another app when it goes off then the banner appears. Consequently I spent a lot of time browsing for a solution.

However, it's not possible to control the style of alert generated by a UILocalNotification I'm afraid :(

You can see from the class reference that there's no provision for it:

http://developer.apple.com/library/IOs/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html

Or in the plist:

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

Best thing to do is tell the user what to do to change the settings.

Chez answered 24/11, 2011 at 16:2 Comment(2)
I'm afraid the absence of any properties in UILocalNotification is not good enough to settle this. For example, there could be a Info.plist key that would specify a default.Rugg
No offense, but I don't consider you authoritative even though you seem to put some effort into this. But I doubt you've looked at the iOS binaries or dug any deeper than reading documentation. Still, I appreciate the effort which is why I've given you a +1.Rugg
L
11

You probably won't find 'authoritative' from your peers here, you should better ask directly to Apple; and the question has already been asked several times on theirs forums and not answered...

The HIG programming guide - http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/TechnologyUsage/TechnologyUsage.html#//apple_ref/doc/uid/TP40006556-CH18-SW1 -

"iOS apps that support local or push notifications can participate in Notification Center in various ways, depending on the user’s preferences."

That last sentence is the only 'authoritative hint' i found.

The USER'S preferences <= you can't force the user ('s preferences). Period. This design choice is clearly the Apple Way (applications' playground IS limited, to ensure the best user experience possible)

As for more authority... maybe shouting ?

NO YOU CAN'T CHOOSE YOUR NOTIFICATIONS DISPLAY STYLE, IT'S THE USER'S CHOICE

Just kidding... Anyway, a workaround might be to provide a way in your application - hint/ tutorial - to push the user to change the alert style himself...

good luck !

Lexicologist answered 29/11, 2011 at 13:30 Comment(1)
I already plan to file a radar once the bounty period is over, when I asked the question I was hoping that I don't have to but it quickly became obvious that this will be the only way to have this answered once and for all ;-)Rugg
J
4

Obviously you don't like hearing no for an answer, but, no.

Jaan answered 28/11, 2011 at 18:55 Comment(4)
I have no problem with the answer "No", but it must be an authoritative "No". So, if you can back that up, for example with a link to some documentation or posting from someone who really has saying in the matter (like an Apple employee or, say, a high profile hacker like someone from iPhone Dev Team), then you'll get the bounty :-)Rugg
Well, I've spend a long time looking and I've not found a solution. Given the time involved I'd say my response is now authoritative, so it would be nice if at least two people would vote on it so that I can can half the bounty :) You'll find it among the other responses....Chez
This is essentially the same question I see asked about once a day: how can my app behave entirely differently from all the others? How can I completely change the iOS UI? This sort of thing isn't ever going to be possible. It doesn't scale. (Maybe your alarm app really does need to be different. But then every fart app would be doing it too.)Jaan
@David Dunham: No, it's not about being different. iOS has two different notification styles and for our use case the alert style makes more sense so we would want to have that as default. And the reason why I want an authoritative answer is exactly so that others can have this solved as well.Rugg
E
0

You can use this line to query the current settings for notification style:

UIRemoteNotificationType* enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

You can check the enabledTypes and then instruct the user to change the notification style in the settings.

Elinaelinor answered 30/6, 2013 at 10:26 Comment(1)
Unfortunately this can only determine that alert is enabled or not but cannot find out the style of the alert. See definition: typedef NS_OPTIONS(NSUInteger, UIRemoteNotificationType) { UIRemoteNotificationTypeNone = 0, UIRemoteNotificationTypeBadge = 1 << 0, UIRemoteNotificationTypeSound = 1 << 1, UIRemoteNotificationTypeAlert = 1 << 2, UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3, } NS_ENUM_AVAILABLE_IOS(3_0);Knuckleduster
H
-2

have you tried

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

in your didFinishLaunching method, this won't help those updating but should enable alerts for those first installing

Hooke answered 30/11, 2011 at 22:43 Comment(4)
You're talking about remote notifications (and miss the UIRemoteNotificationTypeAlert), but I'm talking about local notifications. The documentation doesn't talk about influencing local notifications so I very much doubt it'll have an effect.Rugg
based on what people have commented this call should also be used to enable the app in notification center even if it only uses local notifications.Hooke
This does not change anything - even when setting UIRemoteNotificationTypeAlert at install time still Badge style appears by defaultExsert
Yeah its about "local notifications" here, but still registerForRemoteNotificationTypes will simply ask the user for permission, it does not set the style of notification none, banner or alert. See: developer.apple.com/library/ios/documentation/…Grandiloquence

© 2022 - 2024 — McMap. All rights reserved.