Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential crash automatic properties #608

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Sources/AutomaticProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class AutomaticProperties {
var p = InternalProperties()

#if os(iOS) || os(tvOS)
let screenSize = UIScreen.main.bounds.size
p["$screen_height"] = Int(screenSize.height)
p["$screen_width"] = Int(screenSize.width)
var screenSize: CGSize? = nil
screenSize = UIScreen.main.bounds.size
if let screenSize = screenSize {
p["$screen_height"] = Int(screenSize.height)
p["$screen_width"] = Int(screenSize.width)
}
#if targetEnvironment(macCatalyst)
p["$os"] = "macOS"
p["$os_version"] = ProcessInfo.processInfo.operatingSystemVersionString
Expand Down Expand Up @@ -57,11 +60,10 @@ class AutomaticProperties {
p["$screen_height"] = Int(screenSize.height)
#endif

let infoDict = Bundle.main.infoDictionary
if let infoDict = infoDict {
p["$app_build_number"] = infoDict["CFBundleVersion"]
p["$app_version_string"] = infoDict["CFBundleShortVersionString"]
}
let infoDict = Bundle.main.infoDictionary ?? [:]
p["$app_build_number"] = infoDict["CFBundleVersion"] as? String ?? "Unknown"
p["$app_version_string"] = infoDict["CFBundleShortVersionString"] as? String ?? "Unknown"

p["mp_lib"] = "swift"
p["$lib_version"] = AutomaticProperties.libVersion()
p["$manufacturer"] = "Apple"
Expand Down Expand Up @@ -89,7 +91,7 @@ class AutomaticProperties {
}()

class func deviceModel() -> String {
var modelCode : String
var modelCode : String = "Unknown"
if AutomaticProperties.isiOSAppOnMac() {
// iOS App Running on Apple Silicon Mac
var size = 0
Expand Down