以编程方式获取设备的iOS版本

3 sdk ios swift

我想获得我的应用程序安装在其上的设备的iOS版本.实际上我认为这是我的应用程序的SDK版本.我怎么能通过代码得到它?它有什么功能吗?如果我不能解释它good️,也请原谅.

dah*_*boy 7

将此函数用于swift 4,

1.获取genral中的应用程序版本

func getAppInfo()->String {
    let dictionary = Bundle.main.infoDictionary!
    let version = dictionary["CFBundleShortVersionString"] as! String
    let build = dictionary["CFBundleVersion"] as! String
    return version + "(" + build + ")"
}
Run Code Online (Sandbox Code Playgroud)

2.获取一般的app当前名称

func getAppName()->String {
    let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
    return appName
}
Run Code Online (Sandbox Code Playgroud)

3.获取运行应用程序的设备iOS版本.

func getOSInfo()->String {
    let os = ProcessInfo().operatingSystemVersion
    return String(os.majorVersion) + "." + String(os.minorVersion) + "." + String(os.patchVersion)
}
Run Code Online (Sandbox Code Playgroud)

输入

    print("OS Version: \(getOSInfo())")
    print("App version: \(getAppInfo())")
    print("App Name: \(getAppName())")
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述

  • 如果你想要字符串:`ProcessInfo().operatingSystemVersionString` (2认同)

viv*_*Das 6

使用以下代码获取版本:

迅捷4

let systemVersion = UIDevice.current.systemVersion
Run Code Online (Sandbox Code Playgroud)

目标c

[[UIDevice currentDevice] systemVersion]
Run Code Online (Sandbox Code Playgroud)