当应用程序状态终止/未运行状态后,可能会在某个特定时间后执行某些特定任务。终止应用程序swift后发送本地通知2
func applicationDidEnterBackground(application: UIApplication) {
print("APP in background state") // Working fine
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "backService", userInfo: nil, repeats: true)
}
但是,当应用程序状态去终止状态,然后它不工作?
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)
}
}
通知会触发我同意,但我想在终止状态的某个特定时间后触发。不是在终止状态的时间。 – Haseeb
“终止应用程序迅速2后发送本地通知”;)这是最好的,我可以想出。 –