应用程序终止时间隔运行后台任务

时间:2017-03-20 00:19:04

标签: ios swift background notifications push

我在iOS Swift应用中实现了OneSignal推送通知。我正在从我的服务器发送推送通知,我希望应用程序在收到此消息时执行HTTP Get请求以从我的服务器获取数据。我想检查此数据是否有新数据,并且只有在有任何数据可用时才向用户显示通知。如果这是不可能的,那么即使应用程序被刷掉,我怎样才能每十分钟运行一次后台任务?这是我现在的代码

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {

    Alamofire.request("my-url", method: .get, parameters: my-parameters).reponseJSON {

        // Check for any new data
        if isNewData {
            // Send user a local notification

        } else {
            return
        }

    }
}

0 个答案:

没有答案
相关问题