一、前言
???????????? 目前在App開發中,應用信息& 設備信息的獲取變的必要了。例如:為了解決App崩潰,開發人員就會獲取用戶設備信息和應用的信息提交到一個地方,然后進行分析...等。那么怎么獲取應用信息和設備信息呢?
二 、應用信息的獲取
/**
獲取應用信息
*/
let ApplicationInfoDictionary = Bundle.main.infoDictionary
print(ApplicationInfoDictionary!)
/**
獲取應用的名字
*/
let ApplicationName = ApplicationInfoDictionary?["CFBundleDisplayName"]
print(ApplicationName!)
/**
應用系統的版本
*/
let AppSystemVersion = ApplicationInfoDictionary?["MinimumOSVersion"]
print(AppSystemVersion!)
/**
設備的SDK的 名字
*/
let DeviceName = ApplicationInfoDictionary?["DTSDKName"]
print(DeviceName!)
/**
平臺的名字
*/
let PlatName = ApplicationInfoDictionary?["DTPlatformName"]
print(PlatName!)
/**
平臺的版本
*/
let PlatVersion = ApplicationInfoDictionary?["DTPlatformVersion"]
print(PlatVersion!)
/**
設備的語言
*/
let AppLanguage = ApplicationInfoDictionary?["CFBundleDevelopmentRegion"]
print(AppLanguage!)
/**
App的Identifier表示
該束的唯一標識字符串,該字符串的格式類似 com.yourcompany.yourapp,如果使?用模擬器跑你的應用,這個字段沒有用處,如果你需要把你的應?部署到設備上,你必須?成一個證書,?而在?生成證書的時候,在apple的?網站上需要增加相應的app IDs.這?有一個字段Bundle identidier,如果這個Bundle identidier是一個完整字符串,那么文件中的這個字段必須和后者完全相同,如果app IDs中的字段含有通配符*,那么文件中的字符串必須符合后者的描述。
*/
let AppIdentifier = ApplicationInfoDictionary?["CFBundleIdentifier"]
print(AppIdentifier!)
/**
App 的版本
*/
let AppVersion = ApplicationInfoDictionary?["CFBundleShortVersionString"]
print(AppVersion!)
/**
App 的內部版本
*/
let AppInternalVersion = ApplicationInfoDictionary?["CFBundleVersion"]
print(AppInternalVersion!)
/**
App 所支持的方向
*/
let AppSupportDirection = ApplicationInfoDictionary?["UISupportedInterfaceOrientations"]
print(AppSupportDirection!)
/**
獲取應用工程的名字
*/
let AppProjectName = ApplicationInfoDictionary?["CFBundleName"]
print(AppProjectName!)
/**
獲取應用支持的設備
UIDeviceFamily 設置是一個字符串數組。每個字符串都定義受支持的設備。<string>1</string> 設置定義對 iPhone 和 iPod Touch 的支持。<string>2</string> 設置定義對 iPad 的支持。
*/
let AppSupportDevices = ApplicationInfoDictionary?["UIDeviceFamily"]
print(AppSupportDevices!)
/**
應用安裝包的名字
*/
let AppInstallationPackageName = ApplicationInfoDictionary?["CFBundleExecutable"]
print(AppInstallationPackageName!)
/**
獲取Info.plist 的版本
*/
let InfoPlistVersion = ApplicationInfoDictionary?["CFBundleInfoDictionaryVersion"]
print(InfoPlistVersion!)
三 、設備信息的獲取
/**
獲取設備的一些信息
*/
// TODO : 設備系統的名字
let KDeviceSystemName = UIDevice.current.systemName
print(KDeviceSystemName)
// TODO : 獲取系統的名字
let KDeviceSystemVersion = UIDevice.current.systemVersion
print(KDeviceSystemVersion)
// TODO : 獲取設備的名字
let KDeviceName = UIDevice.current.name
print(KDeviceName)
// TODO : 獲取設置的類型,是 @"iPhone" 還是 @"iPod touch"
let KDeviceType = UIDevice.current.model
print(KDeviceType)
// TODO : 設備區域化型號
let KDevicelocalizedNumber = UIDevice.current.localizedModel
print(KDevicelocalizedNumber)
// TODO : 獲取設備的UUID
let KDeviceUUID = UIDevice.current.identifierForVendor
print(KDeviceUUID!)
//TODO : 獲取設備的朝向
//MARK : 如果 KDeviceOrientation 等于 UIDeviceOrientationUnknown 說明設備朝向信息還沒有確定。
let KDeviceOrientation = UIDevice.current.orientation
print(KDeviceOrientation)
// TODO : 是否生成設備的朝向信息
let isDeviceOrientationInfo = UIDevice.current.isGeneratingDeviceOrientationNotifications
print(isDeviceOrientationInfo)
// TODO : 開啟設備的朝向通知
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
// TODO : 結束設備朝向的通知
UIDevice.current.endGeneratingDeviceOrientationNotifications()
// TODO : 是否開啟電池控制
let isBatteryMonitoring = UIDevice.current.isBatteryMonitoringEnabled
print(isBatteryMonitoring)
// TODO : 獲取設備電池的狀態
// MARK : KDeviceBatteryState = UIDeviceBatteryStateUnknown 說明設備電池不受控制
let KDeviceBatteryState = UIDevice.current.batteryState
print(KDeviceBatteryState)
// TODO : 獲取用戶電池百分比
let KDeviceBatteryLevel = UIDevice.current.batteryLevel
print(KDeviceBatteryLevel)
// TODO : 判斷設備的接近傳感器是否可用
let isProximityMonitoring = UIDevice.current.isProximityMonitoringEnabled
print(isProximityMonitoring)
// TODO : 人臉接近探測器的狀態
// MARK : 如果設備沒有安裝探測器這個一直返回 False
let KDeviceProximityState = UIDevice.current.proximityState
print(KDeviceProximityState)
// TODO :獲取設備是否支持多任務處理
let isMultitasking = UIDevice.current.isMultitaskingSupported
print(isMultitasking)
// TODO : 獲取設備是那種類型的
// MARK : 返回值包含: unspecified 、 pad 、tv 、 carPlay
let KDeviceUserInterfaceIdiom = UIDevice.current.userInterfaceIdiom
print(KDeviceUserInterfaceIdiom)