我试图在每天早上的某个时间通过后台执行来运行特定的函数。这是我想到的...
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 在特定时间启动您的应用程序。
如果您只想在特定时间发送通知,请安排本地通知。如果用户打开您的通知,那么您的应用程序将启动。