
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
How to get the current version of my iOS project in code?
When we build an iOS application, by default it get a version 1.0 and build 0. Whenever we upload a new build to the app store, we need to change the version number. We can update the build number for testing builds. The version and build number are stored in the info.plist file in our project.
Sometimes we might need to access the build or the version number in our application to perform some custom action.
To get the version number we can use the following code and assign it to a variable or constant.
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
To get the build number we can use the below code
Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
For an example, we can use the above code in our viewDidLoad to access these values and print.
override func viewDidLoad() { super.viewDidLoad() let currentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String let currentBuild = Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String print(currentVersion,".",currentBuild) }
When we run the above code we will get our version number followed by a “.” and the build number.
- Related Articles
- How to get the build/version number of an iOS App?
- How to get the current location latitude and longitude in iOS?
- How to take a screenshot of my iOS application in the iOS simulator?
- How to get current date and time from internet in iOS?
- How can I get the current Android SDK version programmatically?
- How to get current country code from Network provider in android?
- How to get current postal code from Network provider in android?
- How can I get the current Android SDK version programmatically using Kotlin?
- How to include CDN Based Version of jQuery in my HTML file?
- How to detect which iOS version is running on the device?
- Current Version of CSS
- How to return a string value version of the current number?
- Which version is my MySQL?
- Get the hash code for the current Int64 instance in C#
- Get the hash code for the current Decimal instance in C#

Advertisements