是否可以更改UILocalNotification的显示持续时间? [英] Is it possible to change the display duration of a UILocalNotification?

查看:215
本文介绍了是否可以更改UILocalNotification的显示持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示本地通知并让它在屏幕上保留的时间超过默认的4-5秒,最好是应用程序本身删除它。我见过其他应用程序(例如Pandora)设法以某种方式设置(也许是推送通知?),但我找不到 UILocalNotification 或<$中的持续时间属性c $ c> UIApplication 类似 presentLocalNotificationNow: scheduleLocalNotification:等方法。 a href =https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html =nofollowtitle =docs>文档或任何我发现的教程完全解决了显示时间问题。这是不能通过本地通知完成的事情吗?

I need to display a local notification and have it remain on screen longer than the default 4-5 seconds, preferably until the app itself removes it. I've seen other apps (e.g. Pandora) that manage to do this somehow (maybe a push notification?), but I can find no duration property on UILocalNotification or in UIApplication methods like presentLocalNotificationNow:, scheduleLocalNotification:, etc. Neither the documentation nor any of the tutorials I've found address the display time at all. Is this something that just can't be done with local notifications?

推荐答案

这里有几个解决方案,我也不建议:

A couple of solutions here and I would not recommend either:

1-您可以要求用户转到设置>通知中心>您的应用。并将警报样式从横幅(默认)更改为警报。这将向用户显示类似于应用程序位于前台时显示的警报的警报。用户必须关闭警报与刚出现/消失的横幅样式通知。除非这是一个企业应用程序,并且你有用户购买,我不会去那条路,因为这可能会惹恼用户。

1- You can request from the user to go to settings > Notification Center > your app. And change the alert style from Banner (default) to Alerts. This will present the user an alert similar to the alert presented when the app is in the foreground. The user would have to dismiss the alert versus the banner style notification that just appears/disappears. Unless this is a corporate app and you have the users buy in, I would not go that route as this could annoy the user.

2-我测试了声音剪辑方法是的,如果你提出一个带剪辑的通知< 30秒;通知将保留在(屏幕顶部)屏幕上,直到声音片段播放完毕。话虽如此,如果用户点击任何音量按钮(例如减少声音),通知甚至会在结束前立即被解雇!我认为,虽然通知的目的是温和的提醒,持续超过典型的4-5秒违反常规,它可能会使用户烦恼(或者用户可能认为某些东西被卡住,手机冻结等等。 )。以下是代码:

2- I tested the sound clip method and yes, if you present a notification with a clip < 30seconds; the notification will stay on the (top of the) screen until the sound clip is finished playing. Having said that, if the user taps any of the volume button (to reduce the sound for example), the notification is immediately dismissed even before its end! I think though that the purpose of the notification is a gentle reminder and, lasting more than the typical 4-5 seconds goes against the norm and, it might annoy the user (or the user might think something is stuck, phone froze, etc..). Here is the code anyway:

UILocalNotification *howLongCanANotificationLast = [[UILocalNotification alloc]init];
howLongCanANotificationLast.alertBody=@"I am a notification";
howLongCanANotificationLast.soundName=@"musicfilename.mp3";
[[UIApplication sharedApplication] presentLocalNotificationNow:howLongCanANotificationLast];

希望这会有所帮助。

这篇关于是否可以更改UILocalNotification的显示持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆