Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active November 25, 2018 18:35
Show Gist options
  • Save vialyx/3dcd767611c5e3f9e1d5f714cd82835d to your computer and use it in GitHub Desktop.
Save vialyx/3dcd767611c5e3f9e1d5f714cd82835d to your computer and use it in GitHub Desktop.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Setup Fetch Interval
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
return true
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Create url which from we will get fresh data
if let url = URL(string: "https://www.vialyx.com") {
// Send request
URLSession.shared.dataTask(with: url, completionHandler: { (data, respone, error) in
// Check Data
guard let `data` = data else { completionHandler(.failed); return }
// Get result from data
let result = String(data: data, encoding: .utf8)
// Print result into console
print("performFetchWithCompletionHandler result: \(String(describing: result))")
// Call background fetch completion with .newData result
completionHandler(.newData)
}).resume()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment