Commit 46126b77 authored by Rebecca Hughes's avatar Rebecca Hughes

Add app version information

parent 7a19ba16
......@@ -90,4 +90,12 @@ console.log("Device Name", DeviceInfo.getSystemName()); // e.g. iPhone OS
console.log("Device Version", DeviceInfo.getSystemVersion()); // e.g. 9.0
console.log("Bundle Id", DeviceInfo.getBundleId()); // e.g. com.learnium.mobile
console.log("Build Number", DeviceInfo.getBuildNumber()); // e.g. 89
console.log("App Version", DeviceInfo.getVersion()); // e.g. 1.1.0
console.log("App Version (Readable)", DeviceInfo.getReadableVersion()); // e.g. 1.1.0.89
```
......@@ -36,6 +36,10 @@ RCT_EXPORT_MODULE()
@"systemVersion": currentDevice.systemVersion,
@"model": currentDevice.model,
@"deviceId": deviceId,
@"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"],
@"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
@"systemManufacturer": @"Apple",
};
}
......
......@@ -11,6 +11,8 @@ import com.facebook.react.bridge.Callback;
import android.os.Build;
import android.provider.Settings.Secure;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import java.util.HashMap;
import java.util.Map;
......@@ -32,10 +34,27 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@Override
public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
PackageManager packageManager = this.reactContext.getPackageManager();
String packageName = this.reactContext.getPackageName();
constants.put("appVersion", "not available");
constants.put("buildNumber", 0);
try {
PackageInfo info = packageManager.getPackageInfo(packageName, 0);
constants.put("appVersion", info.versionName);
constants.put("buildNumber", info.versionCode);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
constants.put("systemName", "Android");
constants.put("systemVersion", Build.VERSION.RELEASE);
constants.put("model", Build.MODEL);
constants.put("deviceId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID));
constants.put("systemManufacturer", Build.MANUFACTURER);
constants.put("bundleId", packageName);
return constants;
}
}
/**
* @providesModule react-native-device-info
*/
var { RNDeviceInfo } = require('react-native').NativeModules;
module.exports = {
getUniqueID: function () {
return RNDeviceInfo.deviceId;
},
getManufacturer: function () {
return "Apple";
},
getModel: function () {
return RNDeviceInfo.model;
},
getSystemName: function () {
return RNDeviceInfo.systemName;
},
getSystemVersion: function () {
return RNDeviceInfo.systemVersion;
}
};
......@@ -15,9 +15,21 @@ module.exports = {
return RNDeviceInfo.model;
},
getSystemName: function () {
return "Android";
return RNDeviceInfo.systemName;
},
getSystemVersion: function () {
return RNDeviceInfo.systemVersion;
},
getBundleId: function() {
return RNDeviceInfo.bundleId;
},
getBuildNumber: function() {
return RNDeviceInfo.buildNumber;
},
getVersion: function() {
return RNDeviceInfo.appVersion;
},
getReadableVersion: function() {
return RNDeviceInfo.appVersion + "." + RNDeviceInfo.buildNumber;
}
};
{
"name": "react-native-device-info",
"version": "0.3.0",
"version": "0.4.0",
"description": "Get device information using react-native",
"main": "deviceinfo.ios.js",
"main": "deviceinfo.js",
"repository": {
"type": "git",
"url": "https://github.com/rebeccahughes/react-native-device-info"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment