I have an IOS app with an Azure back-end, and would like to log certain events, like logins and which versions of the app users are running.
How can I return the version and build number using Swift?
SWIFT 4
//First get the nsObject by defining as an optional AnyObject
let nsObject: AnyObject? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as AnyObject //Then just cast the object as a String, but be careful, you may want to double check for nil
let version = nsObject as! String for anyone interested, there's a nice and neat library called SwifterSwift available at github and also fully documented for every version of swift (see swifterswift.com).
using this library, reading app version and build number would be as easy as this:
import SwifterSwift let buildNumber = UIApplication.shared.buildNumber let version = UIApplication.shared.version let buildNumber = UIApplication.shared.buildNumber and let version = UIApplication.shared.version
CFBundleVersion& CFBundleShortVersionString`. The first is your build version. The other is version number. See here for more info