Last active
November 25, 2018 18:35
-
-
Save vialyx/3dcd767611c5e3f9e1d5f714cd82835d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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