Commit 569fe0ed authored by Rebecca Hughes's avatar Rebecca Hughes

Merge pull request #3 from rebeccahughes/0.5.0

Add deviceId, tweak model on iOS
parents 152f9ece adb9aefc
...@@ -75,6 +75,13 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand ...@@ -75,6 +75,13 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
(Thanks to @chirag04 for writing the instructions) (Thanks to @chirag04 for writing the instructions)
## Release Notes
0.5.0 adds a new parameter; Device Id. On iOS this is the hardware string for the current device (e.g.
"iPhone7,2"). On Android we use the BOARD field which is the name of the underlying board, e.g. "goldfish".
The way that the module gets the device model on iOS has also changed to be based on the Device Id; now
instead of getting a generic product family e.g. "iPhone", it will return the specific model e.g. "iPhone 6".
## Example ## Example
```js ```js
...@@ -84,7 +91,9 @@ console.log("Device Unique ID", DeviceInfo.getUniqueID()); // e.g. FCDBD8EF-62F ...@@ -84,7 +91,9 @@ console.log("Device Unique ID", DeviceInfo.getUniqueID()); // e.g. FCDBD8EF-62F
console.log("Device Manufacturer", DeviceInfo.getManufacturer()); // e.g. Apple console.log("Device Manufacturer", DeviceInfo.getManufacturer()); // e.g. Apple
console.log("Device Model", DeviceInfo.getModel()); // e.g. iPhone console.log("Device Model", DeviceInfo.getModel()); // e.g. iPhone 6
console.log("Device ID", DeviceInfo.getDeviceId()); // e.g. iPhone7,2 / or the board on Android e.g. goldfish
console.log("Device Name", DeviceInfo.getSystemName()); // e.g. iPhone OS console.log("Device Name", DeviceInfo.getSystemName()); // e.g. iPhone OS
......
...@@ -24,18 +24,115 @@ RCT_EXPORT_MODULE() ...@@ -24,18 +24,115 @@ RCT_EXPORT_MODULE()
return dispatch_get_main_queue(); return dispatch_get_main_queue();
} }
- (NSString*) deviceId
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
- (NSString*) deviceName
{
static NSDictionary* deviceNamesByCode = nil;
if (!deviceNamesByCode) {
deviceNamesByCode = @{@"i386" :@"Simulator",
@"x86_64" :@"Simulator",
@"iPod1,1" :@"iPod Touch", // (Original)
@"iPod2,1" :@"iPod Touch", // (Second Generation)
@"iPod3,1" :@"iPod Touch", // (Third Generation)
@"iPod4,1" :@"iPod Touch", // (Fourth Generation)
@"iPod5,1" :@"iPod Touch", // (Fifth Generation)
@"iPod7,1" :@"iPod Touch", // (Sixth Generation)
@"iPhone1,1" :@"iPhone", // (Original)
@"iPhone1,2" :@"iPhone 3G", // (3G)
@"iPhone2,1" :@"iPhone 3GS", // (3GS)
@"iPad1,1" :@"iPad", // (Original)
@"iPad2,1" :@"iPad 2", //
@"iPad2,2" :@"iPad 2", //
@"iPad2,3" :@"iPad 2", //
@"iPad2,4" :@"iPad 2", //
@"iPad3,1" :@"iPad", // (3rd Generation)
@"iPad3,2" :@"iPad", // (3rd Generation)
@"iPad3,3" :@"iPad", // (3rd Generation)
@"iPhone3,1" :@"iPhone 4", // (GSM)
@"iPhone3,2" :@"iPhone 4", // iPhone 4
@"iPhone3,3" :@"iPhone 4", // (CDMA/Verizon/Sprint)
@"iPhone4,1" :@"iPhone 4S", //
@"iPhone5,1" :@"iPhone 5", // (model A1428, AT&T/Canada)
@"iPhone5,2" :@"iPhone 5", // (model A1429, everything else)
@"iPad3,4" :@"iPad", // (4th Generation)
@"iPad3,5" :@"iPad", // (4th Generation)
@"iPad3,6" :@"iPad", // (4th Generation)
@"iPad2,5" :@"iPad Mini", // (Original)
@"iPad2,6" :@"iPad Mini", // (Original)
@"iPad2,7" :@"iPad Mini", // (Original)
@"iPhone5,3" :@"iPhone 5c", // (model A1456, A1532 | GSM)
@"iPhone5,4" :@"iPhone 5c", // (model A1507, A1516, A1526 (China), A1529 | Global)
@"iPhone6,1" :@"iPhone 5s", // (model A1433, A1533 | GSM)
@"iPhone6,2" :@"iPhone 5s", // (model A1457, A1518, A1528 (China), A1530 | Global)
@"iPhone7,1" :@"iPhone 6 Plus", //
@"iPhone7,2" :@"iPhone 6", //
@"iPhone8,1" :@"iPhone 6S", //
@"iPhone8,2" :@"iPhone 6S Plus", //
@"iPad4,1" :@"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2" :@"iPad Air", // 5th Generation iPad (iPad Air) - Cellular
@"iPad4,3" :@"iPad Air", // 5th Generation iPad (iPad Air)
@"iPad4,4" :@"iPad Mini 2", // (2nd Generation iPad Mini - Wifi)
@"iPad4,5" :@"iPad Mini 2", // (2nd Generation iPad Mini - Cellular)
@"iPad4,6" :@"iPad Mini 2", // (2nd Generation iPad Mini)
@"iPad4,7" :@"iPad Mini 3", // (3rd Generation iPad Mini)
@"iPad4,8" :@"iPad Mini 3", // (3rd Generation iPad Mini)
@"iPad4,9" :@"iPad Mini 3", // (3rd Generation iPad Mini)
@"iPad5,1" :@"iPad Mini 4", // (4th Generation iPad Mini)
@"iPad5,2" :@"iPad Mini 4", // (4th Generation iPad Mini)
@"iPad5,3" :@"iPad Air 2", // 6th Generation iPad (iPad Air 2)
@"iPad5,4" :@"iPad Air 2", // 6th Generation iPad (iPad Air 2)
@"iPad6,7" :@"iPad Pro", // iPad Pro
@"iPad6,8" :@"iPad Pro", // iPad Pro
@"AppleTV2,1":@"Apple TV", // Apple TV (2nd Generation)
@"AppleTV3,1":@"Apple TV", // Apple TV (3rd Generation)
@"AppleTV3,2":@"Apple TV", // Apple TV (3rd Generation - Rev A)
@"AppleTV5,3":@"Apple TV", // Apple TV (4th Generation)
};
}
NSString* deviceName = [deviceNamesByCode objectForKey:self.deviceId];
if (!deviceName) {
// Not found on database. At least guess main device type from string contents:
if ([self.deviceId rangeOfString:@"iPod"].location != NSNotFound) {
deviceName = @"iPod Touch";
}
else if([self.deviceId rangeOfString:@"iPad"].location != NSNotFound) {
deviceName = @"iPad";
}
else if([self.deviceId rangeOfString:@"iPhone"].location != NSNotFound){
deviceName = @"iPhone";
}
}
return deviceName;
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
NSUUID *identifierForVendor = [currentDevice identifierForVendor]; NSUUID *identifierForVendor = [currentDevice identifierForVendor];
NSString *deviceId = [identifierForVendor UUIDString]; NSString *uniqueId = [identifierForVendor UUIDString];
return @{ return @{
@"systemName": currentDevice.systemName, @"systemName": currentDevice.systemName,
@"systemVersion": currentDevice.systemVersion, @"systemVersion": currentDevice.systemVersion,
@"model": currentDevice.model, @"model": self.deviceName,
@"deviceId": deviceId, @"deviceId": self.deviceId,
@"uniqueId": uniqueId,
@"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"], @"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"],
@"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], @"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
...@@ -44,3 +141,4 @@ RCT_EXPORT_MODULE() ...@@ -44,3 +141,4 @@ RCT_EXPORT_MODULE()
} }
@end @end
...@@ -52,7 +52,8 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -52,7 +52,8 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("systemName", "Android"); constants.put("systemName", "Android");
constants.put("systemVersion", Build.VERSION.RELEASE); constants.put("systemVersion", Build.VERSION.RELEASE);
constants.put("model", Build.MODEL); constants.put("model", Build.MODEL);
constants.put("deviceId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID)); constants.put("deviceId", Build.BOARD);
constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID));
constants.put("systemManufacturer", Build.MANUFACTURER); constants.put("systemManufacturer", Build.MANUFACTURER);
constants.put("bundleId", packageName); constants.put("bundleId", packageName);
return constants; return constants;
......
...@@ -6,6 +6,9 @@ var { RNDeviceInfo } = require('react-native').NativeModules; ...@@ -6,6 +6,9 @@ var { RNDeviceInfo } = require('react-native').NativeModules;
module.exports = { module.exports = {
getUniqueID: function () { getUniqueID: function () {
return RNDeviceInfo.uniqueId;
},
getDeviceId: function () {
return RNDeviceInfo.deviceId; return RNDeviceInfo.deviceId;
}, },
getManufacturer: function () { getManufacturer: function () {
......
{ {
"name": "react-native-device-info", "name": "react-native-device-info",
"version": "0.4.1", "version": "0.5.0",
"description": "Get device information using react-native", "description": "Get device information using react-native",
"main": "deviceinfo.js", "main": "deviceinfo.js",
"repository": { "repository": {
......
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