终止App的本地横幅通知

时间:2017-02-21 12:49:18

标签: ios swift uilocalnotification

我想在用户退出应用程序时显示横幅通知。在点击该横幅时,我希望我的应用程序打开。

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())

仍然无法正常工作。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

当我在info.plist中为Requires Background Modes设置 App使用CoreBluetooth进行通信时,相同的代码有效。

得到This Answer

的提示

我们希望,Apple不会拒绝我的应用程序。