Commit 0a374b58 authored by Naoto Ida's avatar Naoto Ida

Added iOS/Android support for getting carrier information

parent 589633a9
...@@ -193,7 +193,7 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -193,7 +193,7 @@ var DeviceInfo = require('react-native-device-info');
| Serial Number | `getSerialNumber()` | `string` | Only supported in Android | Serial Number | `getSerialNumber()` | `string` | Only supported in Android
| IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android | IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android
| MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android | MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android
| Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | | |
Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript: Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript:
```js ```js
......
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
@property (nonatomic) bool isEmulator; @property (nonatomic) bool isEmulator;
@end @end
@import CoreTelephony;
@implementation RNDeviceInfo @implementation RNDeviceInfo
@synthesize isEmulator; @synthesize isEmulator;
RCT_EXPORT_MODULE() RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup + (BOOL)requiresMainQueueSetup
{ {
return YES; return YES;
...@@ -31,17 +33,17 @@ RCT_EXPORT_MODULE() ...@@ -31,17 +33,17 @@ RCT_EXPORT_MODULE()
struct utsname systemInfo; struct utsname systemInfo;
uname(&systemInfo); uname(&systemInfo);
NSString* deviceId = [NSString stringWithCString:systemInfo.machine NSString* deviceId = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
if ([deviceId isEqualToString:@"i386"] || [deviceId isEqualToString:@"x86_64"] ) { if ([deviceId isEqualToString:@"i386"] || [deviceId isEqualToString:@"x86_64"] ) {
deviceId = [NSString stringWithFormat:@"%s", getenv("SIMULATOR_MODEL_IDENTIFIER")]; deviceId = [NSString stringWithFormat:@"%s", getenv("SIMULATOR_MODEL_IDENTIFIER")];
self.isEmulator = YES; self.isEmulator = YES;
} else { } else {
self.isEmulator = NO; self.isEmulator = NO;
} }
return deviceId; return deviceId;
} }
...@@ -50,7 +52,7 @@ RCT_EXPORT_MODULE() ...@@ -50,7 +52,7 @@ RCT_EXPORT_MODULE()
static NSDictionary* deviceNamesByCode = nil; static NSDictionary* deviceNamesByCode = nil;
if (!deviceNamesByCode) { if (!deviceNamesByCode) {
deviceNamesByCode = @{@"iPod1,1" :@"iPod Touch", // (Original) deviceNamesByCode = @{@"iPod1,1" :@"iPod Touch", // (Original)
@"iPod2,1" :@"iPod Touch", // (Second Generation) @"iPod2,1" :@"iPod Touch", // (Second Generation)
@"iPod3,1" :@"iPod Touch", // (Third Generation) @"iPod3,1" :@"iPod Touch", // (Third Generation)
...@@ -150,6 +152,13 @@ RCT_EXPORT_MODULE() ...@@ -150,6 +152,13 @@ RCT_EXPORT_MODULE()
return deviceName; return deviceName;
} }
- (NSString *) carrier
{
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
return carrier.carrierName;
}
- (NSString*) userAgent - (NSString*) userAgent
{ {
#if TARGET_OS_TV #if TARGET_OS_TV
...@@ -204,6 +213,7 @@ RCT_EXPORT_MODULE() ...@@ -204,6 +213,7 @@ RCT_EXPORT_MODULE()
@"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null], @"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null],
@"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], @"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
@"systemManufacturer": @"Apple", @"systemManufacturer": @"Apple",
@"carrier": self.carrier ?: [NSNull null],
@"userAgent": self.userAgent, @"userAgent": self.userAgent,
@"timezone": self.timezone, @"timezone": self.timezone,
@"isEmulator": @(self.isEmulator), @"isEmulator": @(self.isEmulator),
......
...@@ -107,6 +107,12 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -107,6 +107,12 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
p.resolve(macAddress); p.resolve(macAddress);
} }
@ReactMethod
public String getCarrier() {
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
return telMgr.getNetworkOperatorName();
}
@Override @Override
public @Nullable Map<String, Object> getConstants() { public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>(); HashMap<String, Object> constants = new HashMap<String, Object>();
...@@ -172,6 +178,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -172,6 +178,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager telMgr = (TelephonyManager) this.reactContext.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
constants.put("phoneNumber", telMgr.getLine1Number()); constants.put("phoneNumber", telMgr.getLine1Number());
} }
constants.put("carrier", this.getCarrier());
return constants; return constants;
} }
} }
...@@ -28,3 +28,4 @@ export function getIPAddress(): Promise<string>; ...@@ -28,3 +28,4 @@ export function getIPAddress(): Promise<string>;
export function getMACAddress(): Promise<string>; export function getMACAddress(): Promise<string>;
export function getPhoneNumber(): string; export function getPhoneNumber(): string;
export function getAPILevel(): number; export function getAPILevel(): number;
export function getCarrier(): string;
...@@ -5,40 +5,40 @@ ...@@ -5,40 +5,40 @@
var RNDeviceInfo = require('react-native').NativeModules.RNDeviceInfo; var RNDeviceInfo = require('react-native').NativeModules.RNDeviceInfo;
module.exports = { module.exports = {
getUniqueID: function () { getUniqueID: function() {
return RNDeviceInfo.uniqueId; return RNDeviceInfo.uniqueId;
}, },
getInstanceID: function() { getInstanceID: function() {
return RNDeviceInfo.instanceId; return RNDeviceInfo.instanceId;
}, },
getSerialNumber: function () { getSerialNumber: function() {
return RNDeviceInfo.serialNumber; return RNDeviceInfo.serialNumber;
}, },
getIPAddress: function () { getIPAddress: function() {
return RNDeviceInfo.getIpAddress(); return RNDeviceInfo.getIpAddress();
}, },
getMACAddress: function () { getMACAddress: function() {
return RNDeviceInfo.getMacAddress(); return RNDeviceInfo.getMacAddress();
}, },
getDeviceId: function () { getDeviceId: function() {
return RNDeviceInfo.deviceId; return RNDeviceInfo.deviceId;
}, },
getManufacturer: function () { getManufacturer: function() {
return RNDeviceInfo.systemManufacturer; return RNDeviceInfo.systemManufacturer;
}, },
getModel: function () { getModel: function() {
return RNDeviceInfo.model; return RNDeviceInfo.model;
}, },
getBrand: function () { getBrand: function() {
return RNDeviceInfo.brand; return RNDeviceInfo.brand;
}, },
getSystemName: function () { getSystemName: function() {
return RNDeviceInfo.systemName; return RNDeviceInfo.systemName;
}, },
getSystemVersion: function () { getSystemVersion: function() {
return RNDeviceInfo.systemVersion; return RNDeviceInfo.systemVersion;
}, },
getAPILevel: function () { getAPILevel: function() {
return RNDeviceInfo.apiLevel; return RNDeviceInfo.apiLevel;
}, },
getBundleId: function() { getBundleId: function() {
...@@ -51,7 +51,7 @@ module.exports = { ...@@ -51,7 +51,7 @@ module.exports = {
return RNDeviceInfo.appVersion; return RNDeviceInfo.appVersion;
}, },
getReadableVersion: function() { getReadableVersion: function() {
return RNDeviceInfo.appVersion + "." + RNDeviceInfo.buildNumber; return RNDeviceInfo.appVersion + '.' + RNDeviceInfo.buildNumber;
}, },
getDeviceName: function() { getDeviceName: function() {
return RNDeviceInfo.deviceName; return RNDeviceInfo.deviceName;
...@@ -74,16 +74,19 @@ module.exports = { ...@@ -74,16 +74,19 @@ module.exports = {
isTablet: function() { isTablet: function() {
return RNDeviceInfo.isTablet; return RNDeviceInfo.isTablet;
}, },
isPinOrFingerprintSet: function () { isPinOrFingerprintSet: function() {
return RNDeviceInfo.isPinOrFingerprintSet; return RNDeviceInfo.isPinOrFingerprintSet;
}, },
getFirstInstallTime: function () { getFirstInstallTime: function() {
return RNDeviceInfo.firstInstallTime; return RNDeviceInfo.firstInstallTime;
}, },
getLastUpdateTime: function () { getLastUpdateTime: function() {
return RNDeviceInfo.lastUpdateTime; return RNDeviceInfo.lastUpdateTime;
}, },
getPhoneNumber: function () { getPhoneNumber: function() {
return RNDeviceInfo.phoneNumber; return RNDeviceInfo.phoneNumber;
} },
getCarrier: function() {
return RNDeviceInfo.carrier;
},
}; };
...@@ -28,4 +28,5 @@ declare module.exports: { ...@@ -28,4 +28,5 @@ declare module.exports: {
getSerialNumber: () => string, getSerialNumber: () => string,
getIPAddress: () => Promise<string>, getIPAddress: () => Promise<string>,
getMACAddress: () => Promise<string>, getMACAddress: () => Promise<string>,
getCarrier: () => string,
} }
...@@ -27,7 +27,7 @@ namespace RNDeviceInfo ...@@ -27,7 +27,7 @@ namespace RNDeviceInfo
} }
private bool IsEmulator(string model) private bool IsEmulator(string model)
{ {
Regex rgx = new Regex("(?i:virtual)"); Regex rgx = new Regex("(?i:virtual)");
return rgx.IsMatch(model); return rgx.IsMatch(model);
} }
...@@ -83,7 +83,7 @@ namespace RNDeviceInfo ...@@ -83,7 +83,7 @@ namespace RNDeviceInfo
model = deviceInfo.SystemProductName; model = deviceInfo.SystemProductName;
hardwareVersion = deviceInfo.SystemHardwareVersion; hardwareVersion = deviceInfo.SystemHardwareVersion;
os = deviceInfo.OperatingSystem; os = deviceInfo.OperatingSystem;
string deviceFamilyVersion = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion; string deviceFamilyVersion = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
ulong version2 = ulong.Parse(deviceFamilyVersion); ulong version2 = ulong.Parse(deviceFamilyVersion);
...@@ -112,6 +112,7 @@ namespace RNDeviceInfo ...@@ -112,6 +112,7 @@ namespace RNDeviceInfo
constants["timezone"] = TimeZoneInfo.Local.Id; constants["timezone"] = TimeZoneInfo.Local.Id;
constants["isEmulator"] = IsEmulator(model); constants["isEmulator"] = IsEmulator(model);
constants["isTablet"] = IsTablet(os); constants["isTablet"] = IsTablet(os);
constants["carrier"] = "not available";
return constants; return constants;
} }
......
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