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?
If you don't know where to find something on Android, the Settings menu is always a good place to start. It's the same for finding out what version of an app you're running. Once in Settings, tap Apps and notifications (or your phone manufacturer's name it).
Select General > iPhone Storage. Wait a moment, and the screen will populate with storage stats for each of your installed apps. Tap the app you want to see the version number for. Next to the app icon you'll see the app name, the version number you're looking for.
Open the Settings app on your Android device. Open the "Applications" and/or "Application Manager" section. Tap on your app to select it. The App Settings Panel has multiple options including App Version, Notifications, and Location.
These are the actual software version numbers, as opposed to the values used for marketing. If you go to Xcode menu > About Xcode, you'll see the Version and Build numbers. If you hit the More Info... button you'll see a bunch of different versions. Since the More Info...
EDIT
Updated for Swift 4.2
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
EDIT
As pointed out by @azdev on the new version of Xcode you will get a compile error for trying my previous solution, to solve this just edit it as suggested to unwrap the bundle dictionary using a !
let nsObject: AnyObject? = Bundle.main.infoDictionary!["CFBundleShortVersionString"]
End Edit
Just use the same logic than in Objective-C but with some small changes
//First get the nsObject by defining as an optional anyObject let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary["CFBundleShortVersionString"] //Then just cast the object as a String, but be careful, you may want to double check for nil let version = nsObject as! String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With