项目开发中有时候需要获取App的版本号,设备的系统版本号,App名称....,Swift中可以通过Struct来获取,实现代码如下:
struct AppInfo {
static let infoDictionary = Bundle.main.infoDictionary
static let appDisplayName: String = Bundle.main.infoDictionary!["CFBundleDisplayName"] as! String //App 名称
static let bundleIdentifier:String = Bundle.main.bundleIdentifier! // Bundle Identifier
static let appVersion:String = Bundle.main.infoDictionary! ["CFBundleShortVersionString"] as! String// App 版本号
static let buildVersion : String = Bundle.main.infoDictionary! ["CFBundleVersion"] as! String //Bulid 版本号
static let iOSVersion:String = UIDevice.current.systemVersion //ios 版本
static let identifierNumber = UIDevice.current.identifierForVendor //设备 udid
static let systemName = UIDevice.current.systemName //设备名称
static let model = UIDevice.current.model // 设备型号
static let localizedModel = UIDevice.current.localizedModel //设备区域化型号
}
网友评论