How to programmatically display version/build number of target in iOS app?

后端 未结 6 1668
广开言路
广开言路 2020-12-04 05:16

How can I programmatically get the value of the target version, like in the image below?

As seen in the Properties window of the target of my Xcode proj

6条回答
  •  时光说笑
    2020-12-04 05:46

    I made an extension for Bundle so it will be easy to use

    extension Bundle {
        var releaseVersionNumber: String? {
            return infoDictionary?["CFBundleShortVersionString"] as? String
        }
    
        var buildVersionNumber: String? {
            return infoDictionary?["CFBundleVersion"] as? String
        }
    
        var applicationName: String {
            return infoDictionary?["CFBundleDisplayName"] as? String ?? "ADKATech"
        }
    
        var applicationReleaseDate: String {
            return infoDictionary?["ApplicationReleaseDate"] as? String ?? Date().description
        }
    
        var applicationReleaseNumber: Int {
            return infoDictionary?["ApplicationReleaseNumber"] as? Int ?? 0
        }
    
        var releaseVersionNumberPretty: String {
            return "\(releaseVersionNumber ?? "1.0.0")"
        }
    
        var buildVersionNumberPretty: String {
            return "\(buildVersionNumber ?? "1")"
        }
    }
    

提交回复
热议问题