Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 终止应用程序swift 2后发送本地通知_Ios_Swift - Fatal编程技术网

Ios 终止应用程序swift 2后发送本地通知

Ios 终止应用程序swift 2后发送本地通知,ios,swift,Ios,Swift,当应用程序状态变为终止/未运行状态时,可以在特定时间后执行特定任务 func applicationDidEnterBackground(application: UIApplication) { print("APP in background state") // Working fine NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "backService", userInfo: n

当应用程序状态变为终止/未运行状态时,可以在特定时间后执行特定任务

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

}

在应用程序运行期间,安排本地通知、取消和重新安排


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

只要你的应用还在运行,就安排一个本地通知、取消和重新安排


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

您实际上没有安排通知。。。当您在本地创建新通知时(可以在
applicationWillTerminate
方法中完成),有一个名为
fireDate
的属性,您可以将其设置为随时发送通知

您实际上没有安排通知。。。当您在本地创建新通知时(可以在
applicationWillTerminate
方法中完成),有一个名为
fireDate
的属性,您可以将其设置为随时发送通知

通知将触发,我同意,但我想在终止状态的某个特定时间后触发。而不是在终止状态时触发。“终止后发送本地通知应用程序swift 2”)这是我能想到的最好的方法。通知将被触发,我同意,但我想在终止状态的某个特定时间后触发。而不是在终止状态的时间。“终止后发送本地通知应用程序swift 2”)这是我能想出的最好办法。在终止时发送通知,但我想在应用程序处于终止状态的某个特定时间后发送。然后将启动日期设置为您希望的任意时间。这就是该属性的全部要点。在终止时发送通知,但我希望在应用程序处于终止状态的某个特定时间后发送。然后将启动日期设置为您希望的任意时间。这就是那片土地的全部意义所在。