每天早上在特定时间快速后台执行

问题描述 投票:0回答:2

我试图在每天早上的某个时间通过后台执行来运行特定的函数。这是我想到的...

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 swift background-process
2个回答
1
投票

您无法强制 iOS 在特定时间启动您的应用程序。

如果您只想在特定时间发送通知,请安排本地通知。如果用户打开您的通知,那么您的应用程序将启动。


© www.soinside.com 2019 - 2024. All rights reserved.