设置应用程序默认的iOS本地通知样式
从 iOS 5 开始,有两种通知样式:横幅和警报(“旧”样式)。用户可以在设置中为每个应用程序设置使用哪种样式。但是,现在默认情况似乎是通知以横幅样式显示。
我使用本地通知来提醒“现在”将发生的事件。横幅出现后不久就会消失(而且还不够明显,人们可以点击它),因此对于这些通知,最好让警报样式的通知保留在屏幕上,直到用户决定执行某项操作(忽略或继续)到应用程序)。
有没有办法通过代码或例如 Info.plist
条目来告诉 iOS 默认情况下应使用警报样式通知(只要用户没有配置其他内容)?
更新:缺乏信息/文档不足以让我解决这个问题。我想要来自权威人士(Apple 员工或像 Erica Sadun 那样的人)的论坛/博客文章之类的东西说这是不可能的,或者如果可能的话我想要解决方案。像“要求用户更改设置”这样的解决方法也不够好。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我想补充一些内容,因为我已经开设了 TSI,不知怎的,我问过这个问题并得到了答复。来自 Quinn“爱斯基摩人!”:
“这取决于您的意思。您可以根据您设置 UILocalNotification 属性(例如alertBody、soundName 等)的方式来控制通知的显示方式。但是,如果您询问解释这些属性的方式(用户可以在“设置”>“通知”中自定义的内容),这些是用户首选项,不会通过任何 API 公开。”
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."
我有一个闹钟应用程序,我也需要此功能。在 iOS5 下,如果用户正在使用另一个应用程序,则该应用程序关闭时会出现横幅。因此我花了很多时间寻找解决方案。
但是,恐怕无法控制 UILocalNotification 生成的警报样式:(
您可以从类参考中看到没有任何规定:
http://developer.apple.com/library/IOs/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html
或在 plist 中:
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
最好的办法是告诉用户该做什么更改设置。
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.
你在这里可能找不到同行的“权威”,你最好直接向苹果询问;这个问题已经在他们的论坛上被问过好几次了,但没有得到解答...
HIG 编程指南 - http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/TechnologyUsage/TechnologyUsage.html#//apple_ref/doc/uid/TP40006556-CH18-SW1 -
最后一句是我发现的唯一“权威提示”。
用户的偏好<=你不能强迫用户(的偏好)。
时期。
这种设计选择显然是Apple Way(应用程序的游乐场是有限的,以确保尽可能最好的用户体验)
至于更多的权限......也许大喊大叫?
不,您无法选择通知显示样式,这是用户的选择
开玩笑...
无论如何,解决方法可能是在您的应用程序中提供一种方法 - 提示/教程 - 推动用户自己更改警报样式......
祝你好运!
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 -
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 !
显然你不喜欢听到“不”的答案,但是,不。
Obviously you don't like hearing no for an answer, but, no.
您可以使用此行查询通知样式的当前设置:
您可以检查
enabledTypes
,然后指示用户更改设置中的通知样式。You can use this line to query the current settings for notification style:
You can check the
enabledTypes
and then instruct the user to change the notification style in the settings.您是否
在 didFinishLaunching 方法中尝试过,这不会帮助那些更新,但应该为首次安装的人启用警报
have you tried
in your didFinishLaunching method, this won't help those updating but should enable alerts for those first installing