问题
I'm working on a VoIP phone for iOS, and if a call comes in while running in the background, I do a presentLocalNotificationNow with a UILocalNotification message to inform the user. This works fine, however the banner expires and rolls off the screen before the user has enough of a chance to swipe and answer. I have tried scheduling further notifications at regular intervals, but that fills up the notification centre and causes the banner to appear to be tumbling.
Is there some way to prevent the banner from disappearing until I cancel it in some manner? Both the Skype app and Bria VoIP app have managed to come up with a solution where the banner stays until the call is answered, or the callee hangs up.
回答1:
The best way to do this is to add a sound to the local notification.
The default notification without a sound lasts 5 seconds as a banner, however you can include a sound that is longer, up to 30 seconds that you can play when the local notification is posted. The banner notification will stay on screen as long as the sound is playing.
回答2:
No. I think it is not possible to control/increment the hiding banner time to display. It is it's default behavior.
But instead of Banner
style you can set Notification
style as Alert
. Which will not hide/disappear until user will click on alert's buttons.
Hope this will help.
来源:https://stackoverflow.com/questions/18370639/keep-uilocalnotification-banner-visible-while-app-is-in-background