Swift 每天早上特定时间后台执行
Swift Background Execution at certain time each morning
我正在尝试 运行 在每天早上的特定时间在后台执行的特定功能。这是我想出的...
func getCurrentTime() { //Is called every minuite by a timer
let date = NSDate()
let formatter = NSDateFormatter()
formatter.timeStyle = .ShortStyle
var stringValue = formatter.stringFromDate(date)
if stringValue == "7:00 AM" {
sendPushAlert()//Defined elsewhere in code, executes desired code
}
}
但是,这不会 运行 在后台(例如,当应用程序未打开时),并且看起来是一种笨拙的处理方式。
那么,如何在每天早上的特定时间运行后台执行?
或者,是否有更好的方法来获取数据以显示在推送通知中?
谢谢!!!!!!
您不能强制 iOS 在特定时间启动您的应用程序。
如果您只想在特定时间发送通知,schedule a local notification。如果用户打开您的通知,您的应用就会启动。
我正在尝试 运行 在每天早上的特定时间在后台执行的特定功能。这是我想出的...
func getCurrentTime() { //Is called every minuite by a timer
let date = NSDate()
let formatter = NSDateFormatter()
formatter.timeStyle = .ShortStyle
var stringValue = formatter.stringFromDate(date)
if stringValue == "7:00 AM" {
sendPushAlert()//Defined elsewhere in code, executes desired code
}
}
但是,这不会 运行 在后台(例如,当应用程序未打开时),并且看起来是一种笨拙的处理方式。
那么,如何在每天早上的特定时间运行后台执行?
或者,是否有更好的方法来获取数据以显示在推送通知中?
谢谢!!!!!!
您不能强制 iOS 在特定时间启动您的应用程序。
如果您只想在特定时间发送通知,schedule a local notification。如果用户打开您的通知,您的应用就会启动。