【发布时间】:2017-02-21 12:49:18
【问题描述】:
我想在用户退出应用程序时显示横幅通知。在点击该横幅时,我希望我的应用程序打开。
func showBanner() {
UIApplication.shared.cancelAllLocalNotifications()
let notif = UILocalNotification.init()
notif.alertBody = "Your Message Here..."
localNotif.soundName = UILocalNotificationDefaultSoundName
UIApplication.shared.presentLocalNotificationNow(notif)
}
如果我将此代码放在applicationDidEnterBackground 中,它可以正常工作;但是,当我把它放在applicationWillTerminate 中时,它没有。
有什么解决方法吗?
编辑:
添加了fireDate,如下所示:
var dc = DateComponents()
dc.second = 2 // 2 seconds from current date time
notif.fireDate = Calendar.current.date(byAdding: dc, to: Date())
还是不行。有什么想法吗?
【问题讨论】:
-
你在哪里称呼这个
showBanner -
-
@Anbu.Karthik 你提供的链接是
applicationWillTerminate。但是,它不起作用。这就是问题所在。 -
@NazmulHasan 发布了答案。
标签: ios swift uilocalnotification