Last active
May 6, 2025 20:27
-
-
Save NathanWalker/3abd41d2205b4e78f5a620f4532b7c45 to your computer and use it in GitHub Desktop.
NativeScript method for getting app version and build info anytime. Works for iOS, Android and even Vision Pro + Meta Quest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Utils } from '@nativescript/core' | |
export function getAppVersionInfo() { | |
let versionName: string; | |
let buildNumber: string; | |
if (__APPLE__) { | |
versionName = NSBundle.mainBundle.objectForInfoDictionaryKey('CFBundleShortVersionString'); | |
buildNumber = NSBundle.mainBundle.objectForInfoDictionaryKey('CFBundleVersion'); | |
} else { | |
const pi = Utils.android | |
.getApplicationContext() | |
.getPackageManager() | |
.getPackageInfo(Utils.android.getApplicationContext().getPackageName(), 0); | |
versionName = pi.versionName; | |
buildNumber = pi.versionCode.toString(); | |
} | |
return { | |
versionName, | |
buildNumber, | |
versionDisplay: `${versionName} (${buildNumber})` | |
}; | |
} | |
// { | |
// versionName: '1.0.0', | |
// buildNumber: '2025', | |
// versionDisplay: '1.0.0 (2025)' | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using something like Sentry and dynamically insert version/build info during CI, you can use
process.env
vars, for example: