Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the App version and build number using Swift?

Tags:

ios

swift

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?

like image 773
Øyvind Vik Avatar asked Sep 22 '14 00:09

Øyvind Vik


People also ask

How do I find app build number?

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).

How do I find app build number iOS?

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.

How do I find out app version?

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.

What is version and build number in Xcode?

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...


1 Answers

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 
like image 135
David Avatar answered Sep 30 '22 09:09

David