I want to show banner notification when user quits the Application. And on tapping that banner I want my Application to open.
func showBanner() {
UIApplication.shared.cancelAllLocalNotifications()
let notif = UILocalNotification.init()
notif.alertBody = "Your Message Here..."
localNotif.soundName = UILocalNotificationDefaultSoundName
UIApplication.shared.presentLocalNotificationNow(notif)
}
If I put this code in applicationDidEnterBackground
it works fine; But, when I put it in applicationWillTerminate
, it doesn't.
Any workaround?
EDIT:
Added fireDate
like following:
var dc = DateComponents()
dc.second = 2 // 2 seconds from current date time
notif.fireDate = Calendar.current.date(byAdding: dc, to: Date())
Still not working. Any idea?