终止应用程序swift 2后发送本地通知 [英] Send local notification after termination app swift 2
本文介绍了终止应用程序swift 2后发送本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在应用程序状态进入终止/未运行状态的某个特定时间后,是否可以执行某些特定任务。
Is is possible to perform some specific task after some specific time when app state goes to terminate/not running state.
func applicationDidEnterBackground(application: UIApplication) {
print("APP in background state") // Working fine
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "backService", userInfo: nil, repeats: true)
}
但当app状态进入终止状态时它不起作用?
But when app state goes to terminate state then its not working?
func applicationWillTerminate(application: UIApplication) {
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "backService", userInfo: nil, repeats: true)
}
我也是尝试
func applicationWillTerminate(application: UIApplication) {
let application = UIApplication.sharedApplication()
self.applicationDidEnterBackground(application)
application.beginBackgroundTaskWithExpirationHandler {
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "backService", userInfo: nil, repeats: true)
}
}
推荐答案
您实际上并未安排通知......当您创建本地的新通知,可以在 applicationWillTerminate
方法中完成,有一个名为 fireDate
的属性,您可以将其设置为通知随时发送。
You're not actually scheduling a notification... When you create a new notification locally, which can be done in the applicationWillTerminate
method, there's a property called fireDate
which you can set to have the notification get sent whenever you want to.
这篇关于终止应用程序swift 2后发送本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文