Je souhaite afficher une notification de bannière lorsque l'utilisateur quitte l'application. Et en appuyant sur cette bannière, je veux que mon application s'ouvre.Notification de bannière locale pour mettre fin à l'application
func showBanner() {
UIApplication.shared.cancelAllLocalNotifications()
let notif = UILocalNotification.init()
notif.alertBody = "Your Message Here..."
localNotif.soundName = UILocalNotificationDefaultSoundName
UIApplication.shared.presentLocalNotificationNow(notif)
}
Si je mets ce code dans applicationDidEnterBackground
il fonctionne très bien; Mais, quand je le mets en applicationWillTerminate
, ce n'est pas le cas.
Une solution de contournement?
EDIT:
Ajouté fireDate
comme suit:
var dc = DateComponents()
dc.second = 2 // 2 seconds from current date time
notif.fireDate = Calendar.current.date(byAdding: dc, to: Date())
ne fonctionne toujours pas. Une idée?
où vous appelez ceci 'showBanner' –
@ Anbu.Karthik Cela fonctionne quand je le mets avec' applicationDidEnterBackground' Mais cela ne fonctionne pas quand je le mets dans 'applicationWillTerminate' comme mentionné dans queston. –
voir ceci http://stackoverflow.com/questions/16806293/what-is-the-delegate-method-that-will-called-when-closing-an-iphone-app-by-press –