Created
April 30, 2019 17:58
-
-
Save adamkaplan/a0fb391dfc6ea640f980a95a8b76abd3 to your computer and use it in GitHub Desktop.
Revisions
-
adamkaplan created this gist
Apr 30, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ public class UserAgent { public static let userAgent: String? = { guard let info = Bundle.main.infoDictionary, let appNameRaw = info["CFBundleDisplayName"] ?? info[kCFBundleIdentifierKey as String], let appVersionRaw = info[kCFBundleVersionKey as String], let appName = appNameRaw as? String, let appVersion = appVersionRaw as? String else { return nil } #if canImport(UIKit) let scale: String if #available(iOS 4, *) { scale = String(format: "%0.2f", UIScreen.main.scale) } else { scale = "1.0" } let model = UIDevice.current.model let os = UIDevice.current.systemVersion let ua = "\(appName)/\(appVersion) (\(model); iOS \(os); Scale/\(scale))" #else let ua = "\(appName)/\(appVersion)" #endif return ua }() }