한 번 만들어두면 쓸때 편한 앱 기본 정보 조회
//앱 버전 조회
func currentAppVersion() -> String {
if let info: [String: Any] = Bundle.main.infoDictionary,
let currentVersion: String
= info["CFBundleShortVersionString"] as? String {
return currentVersion
}
return "nil"
}
//앱 bundle 조회
func bundleIdentifier() -> String{
if let value = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String {
print("bundle", value)
return value
}
return ""
}
//app 이름 조회
func appName() -> String {
if let info: [String: Any] = Bundle.main.infoDictionary,
let appName: String
= info["CFBundleName"] as? String {
return appName
}
return "app name"
}
// 디바이스 모델 조회
func getModel() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let model = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return model
}
'iOS > Swift' 카테고리의 다른 글
Info.plist에 중요 정보 숨기고 조회하기 (0) | 2023.11.13 |
---|---|
third party library into private cocoapods module (0) | 2023.07.17 |
create module with private cocoapods (0) | 2023.07.10 |
[ios - swift] 화면 터치시UITextField 키보드 내리기 및 스크롤 처리 (0) | 2023.04.11 |
[ios - swift] coremotion을 이용한 걸음수 조회 (0) | 2023.02.22 |