Created
December 5, 2022 08:59
-
-
Save iamchiwon/614fe7e9dc0add33eade7c506c349ca2 to your computer and use it in GitHub Desktop.
This file contains 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
class System { | |
func openAppSetting() { | |
if let bundleId = Bundle.main.bundleIdentifier, | |
let settingUrl = URL(string: UIApplication.openSettingsURLString + bundleId), | |
UIApplication.shared.canOpenURL(settingUrl) { | |
UIApplication.shared.open(settingUrl, options: [:]) { _ in } | |
} | |
} | |
func isSystemPushAllowed(completion: @escaping (Bool) -> Void) { | |
UNUserNotificationCenter.current().getNotificationSettings { settings in | |
if settings.authorizationStatus == .notDetermined || settings.authorizationStatus == .denied { | |
completion(false) | |
} else { | |
completion(true) | |
} | |
} | |
} | |
func currentApplicationVersion() -> String { | |
if let info = Bundle.main.infoDictionary, | |
let currentVersion = info["CFBundleShortVersionString"] as? String { | |
return currentVersion | |
} | |
return "" | |
} | |
func currentApplicationBuildNumber() -> String { | |
if let info = Bundle.main.infoDictionary, | |
let currentVersion = info["CFBundleVersion"] as? String { | |
return currentVersion | |
} | |
return "" | |
} | |
func appStoreLatestVersion() -> Observable<String> { | |
return Observable.create { emitter in | |
let url = URL(string: "https://itunes.apple.com/lookup?id=\(APP_ID)")! | |
let task = URLSession.shared.dataTask(with: URLRequest(url: url, cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalCacheData)) { data, _, error in | |
guard error == nil, let data = data else { | |
emitter.onNext("") | |
return | |
} | |
guard let json = try? JSON(data: data), | |
let results = json["results"].array, | |
results.count > 0, | |
let version = results[0]["version"].string else { | |
emitter.onNext("") | |
return | |
} | |
emitter.onNext(version) | |
} | |
task.resume() | |
return Disposables.create { | |
task.cancel() | |
} | |
}.take(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment