Last active
December 11, 2020 03:03
-
-
Save stevenchou1130/9433093b066862102680499f8e6e0b11 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 | |
import SwiftyJSON | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
self.checkAppVersion() | |
return true | |
} | |
func checkAppVersion() { | |
let link = "https://itunes.apple.com/lookup?bundleId=com.###.YourBundleID" | |
let url: URL = URL(string: link)! | |
let session = URLSession.shared | |
let request = NSMutableURLRequest(url: url) | |
request.httpMethod = Constants.HttpMethod.get | |
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringCacheData | |
let task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in | |
guard let data: Data = data, let _: URLResponse = response, error == nil else { | |
print("ERROR at AppDelegate(checkAppVersion): Fetch App Info fail)") | |
return | |
} | |
self.extractJSON(from: data) | |
}) | |
task.resume() | |
} | |
func extractJSON(from data: Data) { | |
do { | |
let json = try JSON(data: data) | |
print(json) | |
} catch { | |
print("ERROR at AppDelegate(extractJSON): \(error)") | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment