gpt4 book ai didi

ios - 终止app swift 2后发送本地通知

转载 作者:行者123 更新时间:2023-11-28 08:45:41 24 4
gpt4 key购买 nike

当应用程序状态进入终止/未运行状态时,可以在某个特定时间后执行某些特定任务。

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

}

最佳答案

只要您的应用程序正在运行,就可以安排本地通知、取消和重新安排

然后如果它被关闭,通知将不再被取消并且会触发!

关于ios - 终止app swift 2后发送本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35435161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com