Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set timeout for UILocalNotification (remove it from lockscreen and notification center after some time)

I would like to set a UILocalNotification that will disappear from the lock screen and the notification center after five minutes (if the user won't tap on it).

Can I set a timeout for the notification? Or maybe fire another notification that will delete it?

like image 742
Chiko Avatar asked Apr 29 '14 12:04

Chiko


1 Answers

I believe Facebook does this by sending a silent push notification from their servers that triggers this code in the app:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];

To keep the solution entirely local to the device, you can set an NSTimer that can then trigger the above code at the proper interval. This comes with the huge caveat that if your app is suspended when in the background your timer won't fire until it is brought back an active state.

like image 143
jszumski Avatar answered Oct 17 '22 01:10

jszumski