Skip to content

Commit ea22960

Browse files
Dan Williamsalvaromb
authored andcommitted
Add bundleIdentifier support to Android (#21)
* Added 'bundleIdentifier' support to Android * Updated documentation
1 parent d4cd14e commit ea22960

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# react-native-version-number
33
<img src="https://travis-ci.org/APSL/react-native-version-number.svg?branch=master" />
44

5-
Returns the `CFBundleShortVersionString` and the `CFBundleVersion` and `bundleIdentifier` on IOS. For Android, returns the `versionName` and `versionCode`.
5+
Returns the `CFBundleShortVersionString` and the `CFBundleVersion` and `bundleIdentifier` on IOS. For Android, returns the `versionName`, `versionCode` and `applicationId`.
66

77

88
| | iOS | Android | Example |
99
| --- | --- | --- | --- |
1010
| appVersion | `CFBundleShortVersionString` | `versionName` | `1.0.2` |
1111
| buildVersion | `CFBundleVersion` | `versionCode` | `42` |
12-
| bundleIdentifier | `bundleIdentifier` | | `com.foo.bar.MyApp`|
12+
| bundleIdentifier | `bundleIdentifier` | `applicationId` | `com.foo.bar.MyApp`|
1313

1414

1515
## Getting started
@@ -28,8 +28,7 @@ import VersionNumber from 'react-native-version-number';
2828

2929
console.log(VersionNumber.appVersion);
3030
console.log(VersionNumber.buildVersion);
31-
32-
console.log(VersionNumber.bundleIdentifier); // iOS only
31+
console.log(VersionNumber.bundleIdentifier);
3332

3433
```
3534

android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class RNVersionNumberModule extends ReactContextBaseJavaModule {
1919

2020
private static final String APP_VERSION = "appVersion";
2121
private static final String APP_BUILD = "buildVersion";
22+
private static final String APP_ID = "bundleIdentifier";
2223

2324
public RNVersionNumberModule(ReactApplicationContext reactContext) {
2425
super(reactContext);
@@ -38,6 +39,7 @@ public Map<String, Object> getConstants() {
3839
try {
3940
constants.put(APP_VERSION, packageManager.getPackageInfo(packageName, 0).versionName);
4041
constants.put(APP_BUILD, packageManager.getPackageInfo(packageName, 0).versionCode);
42+
constants.put(APP_ID, packageName);
4143
} catch (NameNotFoundException e) {
4244
e.printStackTrace();
4345
}

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ const { RNVersionNumber } = NativeModules;
66

77
type VersionObject = {
88
appVersion: string,
9-
buildVersion: string
10-
}
9+
buildVersion: string,
10+
bundleIdentifier: string,
11+
};
1112

1213
const VersionNumber: VersionObject = {
1314
appVersion: RNVersionNumber.appVersion,
1415
buildVersion: RNVersionNumber.buildVersion,
15-
bundleIdentifier: RNVersionNumber.bundleIdentifier
16-
}
16+
bundleIdentifier: RNVersionNumber.bundleIdentifier,
17+
};
1718

1819
export default VersionNumber;

0 commit comments

Comments
 (0)