Loading README.md +1 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ var DeviceInfo = require('react-native-device-info'); | Serial Number | `getSerialNumber()` | `string` | Only supported in Android | IP Address | `getIPAddress()` | `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: ```js Loading RNDeviceInfo/RNDeviceInfo.m +15 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ @property (nonatomic) bool isEmulator; @end @import CoreTelephony; @implementation RNDeviceInfo @synthesize isEmulator; Loading Loading @@ -150,6 +152,13 @@ RCT_EXPORT_MODULE() return deviceName; } - (NSString *) carrier { CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [netinfo subscriberCellularProvider]; return carrier.carrierName; } - (NSString*) userAgent { #if TARGET_OS_TV Loading Loading @@ -204,6 +213,7 @@ RCT_EXPORT_MODULE() @"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null], @"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], @"systemManufacturer": @"Apple", @"carrier": self.carrier ?: [NSNull null], @"userAgent": self.userAgent, @"timezone": self.timezone, @"isEmulator": @(self.isEmulator), Loading android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,12 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { p.resolve(macAddress); } @ReactMethod public String getCarrier() { TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE); return telMgr.getNetworkOperatorName(); } @Override public @Nullable Map<String, Object> getConstants() { HashMap<String, Object> constants = new HashMap<String, Object>(); Loading Loading @@ -172,6 +178,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { TelephonyManager telMgr = (TelephonyManager) this.reactContext.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); constants.put("phoneNumber", telMgr.getLine1Number()); } constants.put("carrier", this.getCarrier()); return constants; } } deviceinfo.d.ts +1 −0 Original line number Diff line number Diff line Loading @@ -28,3 +28,4 @@ export function getIPAddress(): Promise<string>; export function getMACAddress(): Promise<string>; export function getPhoneNumber(): string; export function getAPILevel(): number; export function getCarrier(): string; deviceinfo.js +20 −17 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ module.exports = { return RNDeviceInfo.appVersion; }, getReadableVersion: function() { return RNDeviceInfo.appVersion + "." + RNDeviceInfo.buildNumber; return RNDeviceInfo.appVersion + '.' + RNDeviceInfo.buildNumber; }, getDeviceName: function() { return RNDeviceInfo.deviceName; Loading Loading @@ -85,5 +85,8 @@ module.exports = { }, getPhoneNumber: function() { return RNDeviceInfo.phoneNumber; } }, getCarrier: function() { return RNDeviceInfo.carrier; }, }; Loading
README.md +1 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ var DeviceInfo = require('react-native-device-info'); | Serial Number | `getSerialNumber()` | `string` | Only supported in Android | IP Address | `getIPAddress()` | `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: ```js Loading
RNDeviceInfo/RNDeviceInfo.m +15 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ @property (nonatomic) bool isEmulator; @end @import CoreTelephony; @implementation RNDeviceInfo @synthesize isEmulator; Loading Loading @@ -150,6 +152,13 @@ RCT_EXPORT_MODULE() return deviceName; } - (NSString *) carrier { CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [netinfo subscriberCellularProvider]; return carrier.carrierName; } - (NSString*) userAgent { #if TARGET_OS_TV Loading Loading @@ -204,6 +213,7 @@ RCT_EXPORT_MODULE() @"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null], @"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], @"systemManufacturer": @"Apple", @"carrier": self.carrier ?: [NSNull null], @"userAgent": self.userAgent, @"timezone": self.timezone, @"isEmulator": @(self.isEmulator), Loading
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,12 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { p.resolve(macAddress); } @ReactMethod public String getCarrier() { TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE); return telMgr.getNetworkOperatorName(); } @Override public @Nullable Map<String, Object> getConstants() { HashMap<String, Object> constants = new HashMap<String, Object>(); Loading Loading @@ -172,6 +178,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { TelephonyManager telMgr = (TelephonyManager) this.reactContext.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); constants.put("phoneNumber", telMgr.getLine1Number()); } constants.put("carrier", this.getCarrier()); return constants; } }
deviceinfo.d.ts +1 −0 Original line number Diff line number Diff line Loading @@ -28,3 +28,4 @@ export function getIPAddress(): Promise<string>; export function getMACAddress(): Promise<string>; export function getPhoneNumber(): string; export function getAPILevel(): number; export function getCarrier(): string;
deviceinfo.js +20 −17 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ module.exports = { return RNDeviceInfo.appVersion; }, getReadableVersion: function() { return RNDeviceInfo.appVersion + "." + RNDeviceInfo.buildNumber; return RNDeviceInfo.appVersion + '.' + RNDeviceInfo.buildNumber; }, getDeviceName: function() { return RNDeviceInfo.deviceName; Loading Loading @@ -85,5 +85,8 @@ module.exports = { }, getPhoneNumber: function() { return RNDeviceInfo.phoneNumber; } }, getCarrier: function() { return RNDeviceInfo.carrier; }, };