我想在用户退出应用程序时显示横幅通知。在点击该横幅时,我希望我的应用程序打开。
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())
仍然无法正常工作。有什么想法吗?
答案 0 :(得分:1)
当我在info.plist
中为Requires Background Modes
设置 App使用CoreBluetooth进行通信时,相同的代码有效。
我们希望,Apple不会拒绝我的应用程序。