为应用程序设置默认的 iOS 本地通知样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8229385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:32:24  来源:igfitidea点击:

Set default iOS local notification style for application

iosios5uilocalnotificationlocalnotification

提问by DarkDust

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.

从 iOS 5 开始,有两种通知样式:横幅和警报(“旧”样式)。用户可以在设置中为每个应用程序设置使用哪种样式。但是,现在的默认设置似乎是通知以横幅样式显示。

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.plistentries to tell iOS that the alert style notifications should be used by default (as long as the user hasn't configured something else)?

有没有办法通过代码或例如Info.plist条目告诉 iOS 默认情况下应该使用警报样式通知(只要用户没有配置其他东西)?

Update: The absenceof 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.

更新缺乏信息/文件不足以让我解决这个问题。我想要来自权威人士(Apple 员工或 Erica Sadun 之类的人)的论坛/博客帖子之类的东西,说这是不可能的,或者如果可能,那么我想要解决方案。像“要求用户更改设置”这样的解决方法也不够好。

采纳答案by IBG

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!":

我想补充一些东西,因为我打开了一个 TSI,不知何故我问过这个问题并得到了回答。来自奎因“爱斯基摩人!”:

"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."

“这取决于您的意思。您可以根据您设置 UILocalNotification 属性(例如 alertBody、soundName 等)的方式来控制通知的显示方式。但是,如果您询问这些属性的方式被解释(用户可以在“设置”>“通知”中自定义的内容),这些是用户首选项,不会通过任何 API 公开。”

回答by tarmes

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.

我有一个警报应用程序,我也需要此功能。在 iOS5 下,如果用户在其他应用程序关闭时使用其他应用程序,则会出现横幅。因此,我花了很多时间浏览解决方案。

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

但是,恐怕无法控制 UILocalNotification 生成的警报样式:(

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

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

Or in the plist:

或者在 plist 中:

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

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.

最好的办法是告诉用户如何更改设置。

回答by Vinzzz

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-

HIG 编程指南 - 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."

“支持本地或推送通知的 iOS 应用程序可以通过各种方式参与通知中心,这取决于用户的偏好。”

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)

用户的偏好 <= 你不能强迫用户(的偏好)。时期。这种设计选择显然是 Apple 方式(应用程序的游乐场是有限的,以确保最佳的用户体验)

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 !

祝你好运 !

回答by David Dunham

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

显然你不喜欢听到“不”的回答,但是,不。

回答by voyager

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

您可以使用此行查询通知样式的当前设置:

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

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

您可以在设置中勾选enabledTypes然后指示用户更改通知样式。

回答by zambono

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

在你的 didFinishLaunching 方法中,这对那些更新没有帮助,但应该为那些第一次安装的人启用警报