小编R.K*_*ini的帖子

如何在背景中的特定日期时间在swift中运行任务,无论应用程序是打开还是关闭

我正在处理报警应用程序,我需要在特定时间安排报警,我scheduleLocalNotification用于安排报警,它可以正常工作.但是我需要在触发警报之前运行到我的API服务器的请求.在该请求中,我想检查从API服务器返回的一些参数,如果满足某些条件.

如果任何人有一个在特定日期运行的方法 - swift的时间请帮助我

 func addAlarm (newAlarm: Alarm) {
    // Create persistent dictionary of data
    var alarmDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ALARMS_KEY) ?? Dictionary()
    // Copy alarm object into persistent data
    alarmDictionary[newAlarm.UUID] = newAlarm.toDictionary()
    // Save or overwrite data
    NSUserDefaults.standardUserDefaults().setObject(alarmDictionary, forKey: ALARMS_KEY)

    scheduleNotification(newAlarm, category: "ALARM_CATEGORY")
    scheduleNotification(newAlarm, category: "FOLLOWUP_CATEGORY")

}

    /* NOTIFICATION FUNCTIONS */
func scheduleNotification (alarm: Alarm, category: String) {
    let notification = UILocalNotification()
    notification.category = category
    notification.repeatInterval = NSCalendarUnit.Day
    switch category {
    case "ALARM_CATEGORY":
        notification.userInfo   = ["UUID": alarm.UUID] …
Run Code Online (Sandbox Code Playgroud)

iphone background-process ios uilocalnotification swift

5
推荐指数
1
解决办法
1653
查看次数