终止应用程序的本地横幅通知 [英] Local banner notification for terminating App
本文介绍了终止应用程序的本地横幅通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用户退出应用程序时显示横幅通知.在点击那个横幅时,我希望我的应用程序打开.
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)
}
如果我把这段代码放在 applicationDidEnterBackground
中,它工作正常;但是,当我把它放在 applicationWillTerminate
中时,它没有.
If I put this code in applicationDidEnterBackground
it works fine; But, when I put it in applicationWillTerminate
, it doesn't.
有什么解决方法吗?
添加了fireDate
,如下所示:
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?
推荐答案
当我在 info.plist
中的 App 通信使用 CoreBluetooth 中为 设置时,相同的代码有效>需要后台模式
.
The same code works when I set in App communicates using CoreBluetooth in info.plist
for Requires Background Modes
.
从这个答案
希望苹果不会拒绝我的应用程序.
Let's hope, Apple does not reject my App.
这篇关于终止应用程序的本地横幅通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文