Unverified Commit f7a01b28 authored by Viktor Dlouhy's avatar Viktor Dlouhy Committed by GitHub
Browse files

Merge branch 'master' into master

parents eaca0b12 aa056392
Loading
Loading
Loading
Loading
+55 −1
Original line number Diff line number Diff line
## Release Notes

### Upcoming

- Make play-services optional (https://github.com/rebeccahughes/react-native-device-info/pull/226)
- Critical fix on WIFI STATE (https://github.com/rebeccahughes/react-native-device-info/pull/249)
- Added `getTotalMemory` and `getMaxMemory` (https://github.com/rebeccahughes/react-native-device-info/pull/289)

### 0.12.0

- Get real WebView UserAgent on Android (https://github.com/rebeccahughes/react-native-device-info/pull/207)
- Add DeviceUID.h to public headers (https://github.com/rebeccahughes/react-native-device-info/pull/217)
- Add `getPhoneNumber` (https://github.com/rebeccahughes/react-native-device-info/pull/174)
- Fix typescript definitions (https://github.com/rebeccahughes/react-native-device-info/pull/221)
- Add `getFirstInstallTime` and `getLastInstallTime` (https://github.com/rebeccahughes/react-native-device-info/pull/222)
- Added version check and permission to work with Android API >= 16 (https://github.com/rebeccahughes/react-native-device-info/pull/225)
- Added device detection even when in an iOS emulator (https://github.com/rebeccahughes/react-native-device-info/pull/224)
- Add support for new iPhone, iPad, and Apple TV models (https://github.com/rebeccahughes/react-native-device-info/pull/230)
- Add android only `getAPILevel` method (https://github.com/rebeccahughes/react-native-device-info/pull/232)
- Add Android support for serial number, IP, and MAC address (https://github.com/rebeccahughes/react-native-device-info/pull/150)
- Add tvOS support (https://github.com/rebeccahughes/react-native-device-info/pull/235)
- Add flow types
- Fix getCurrentActivity() null crash in Android (https://github.com/rebeccahughes/react-native-device-info/pull/247)

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/1aafc6f0b20d7cd6f0939ea5370e9899e4914c93...master)

### 0.11.0

- Add support for RN > 0.47
- Update typescript definitions

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/5b869cdd5e16b65cbe4e85a565aa331bd7546b89...1aafc6f0b20d7cd6f0939ea5370e9899e4914c93)

### 0.10.2

- Add typescript definitions

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/f3967862711892615e7f51d49d0034ee134f3e3d...5b869cdd5e16b65cbe4e85a565aa331bd7546b89)

### 0.10.1

- Add `isPinOrFingerprintSet` method
- Add support for RN > 0.40

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/c843144ea872a79f4d53a53b32f72511fbfc8d8b...f3967862711892615e7f51d49d0034ee134f3e3d)

### 0.10.0

- Semver fix

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/e8bfe5ea8d5f5414f2f97f35a5d02b611cbe39e3...c843144ea872a79f4d53a53b32f72511fbfc8d8b)

### 0.9.8

[Diff](https://github.com/rebeccahughes/react-native-device-info/compare/668996c64e23f477fc8156cdc43a49198b4fdd20...e8bfe5ea8d5f5414f2f97f35a5d02b611cbe39e3)

### 0.9.7

Several bugfixes and detecting if device is a tablet
+32 −27
Original line number Diff line number Diff line
@@ -163,35 +163,40 @@ See [CHANGELOG.md](https://github.com/rebeccahughes/react-native-device-info/blo
var DeviceInfo = require('react-native-device-info');
// or import DeviceInfo from 'react-native-device-info';
```

| Name                       | Method                             | Return                                                                                        | Notes                                                                                                               |
| :------------------------- | :-------------------------------   | :-------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------    |
| Device Unique ID           | `getUniqueID()`                    | FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9                                                          | This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled. |
| Device Manufacturer        | `getManufacturer()`                | Apple                                                                                         |                                                                                                                  |
| Device Brand               | `getBrand()`                       | Apple / htc / Xiaomi                                                                          |                                                                                                                  |
| Device Model               | `getModel()`                       | iPhone 6                                                                                      |                                                                                                                  |
| Device ID                  | `getDeviceId()`                    | iPhone7,2                                                                                     | Or the board on Android e.g. goldfish                                                                            |
| System Name                | `getSystemName()`                  | iPhone OS                                                                                     |                                                                                                                  |
| System Version             | `getSystemVersion()`               | 9.0                                                                                           |                                                                                                                  |
| Bundle ID                  | `getBundleId()`                    | com.learnium.mobile                                                                           |                                                                                                                  |
| Build Number               | `getBuildNumber()`                 | 89                                                                                            |                                                                                                                  |
| App Version                | `getVersion()`                     | 1.1.0                                                                                         |                                                                                                                  |
| App Version (Readable)     | `getReadableVersion()`             | 1.1.0.89                                                                                      |                                                                                                                  |
| Device Name                | `getDeviceName()`                  | Becca's iPhone 6                                                                              |                                                                                                                  |
| User Agent                 | `getUserAgent()`                   | Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D) |                                                                                                                  |
| Device Locale              | `getDeviceLocale()`                | en-US                                                                                         |                                                                                                                  |
| Device Country             | `getDeviceCountry()`               | US                                                                                            |                                                                                                                  |
| Timezone                   | `getTimezone()`                    | America/Mexico_City                                                                           |                                                                                                                  |
| App Instance ID            | `getInstanceID()`                  |                                                                                               | ANDROID ONLY - see https://developers.google.com/instance-id/                                                    |
| App is running in emulator | `isEmulator()`                     | true                                                                                          | if app is running in emulator return true                                                                        |
| App is running on a tablet | `isTablet()`                       | true                                                                                          | if app is running on a tablet return true                                                                        |
| PIN or fingerprint set     | `isPinOrFingerprintSet()(callback)`|                                                                                               | Only supported in Android and iOS 9.0 and above
| Phone Number               | `getPhoneNumber()`                 | "2348675309" or "" or null                                                                    | Only supported in Android
| First Install Time         | `getFirstInstallTime()`            | 1505607068808                                                                                 | Only supported in Android                                                                                          |
| Last Install Time          | `getLastUpdateTime()`              | 1505607068808                                                                                 | Only supported in Android                                                                                          |
| Device Unique ID           | `getUniqueID()`                    | `string` e.g. "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"                                          | This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled.    |
| Device Manufacturer        | `getManufacturer()`                | `string` e.g. "Apple"                                                                         |                                                                                                                     |
| Device Brand               | `getBrand()`                       | `string` e.g. "Apple / htc / Xiaomi"                                                          |                                                                                                                     |
| Device Model               | `getModel()`                       | `string` e.g. "iPhone 6"                                                                      |                                                                                                                     |
| Device ID                  | `getDeviceId()`                    | `string` e.g. "iPhone7,2"                                                                     | Or the board on Android e.g. goldfish                                                                               |
| System Name                | `getSystemName()`                  | `string` e.g. "iPhone OS"                                                                     |                                                                                                                     |
| System Version             | `getSystemVersion()`               | `string` e.g. "9.0"                                                                           |                                                                                                                     |
| Bundle ID                  | `getBundleId()`                    | `string` e.g. "com.learnium.mobile"                                                           |                                                                                                                     |
| Build Number               | `getBuildNumber()`                 | `string` e.g. "89"                                                                            |                                                                                                                     |
| App Version                | `getVersion()`                     | `string` e.g. "1.1.0"                                                                         |                                                                                                                     |
| App Version (Readable)     | `getReadableVersion()`             | `string` e.g. "1.1.0.89"                                                                      |                                                                                                                     |
| Device Name                | `getDeviceName()`                  | `string` e.g. "Becca's iPhone 6"                                                              |                                                                                                                     |
| User Agent                 | `getUserAgent()`                   | `string` e.g. "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.009; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36" |                                |
| Device Locale              | `getDeviceLocale()`                | `string` e.g. "en-US"                                                                         |                                                                                                                     |
| Device Country             | `getDeviceCountry()`               | `string` e.g. "US"                                                                            |                                                                                                                     |
| Timezone                   | `getTimezone()`                    | `string` e.g. "America/Mexico_City"                                                           |                                                                                                                     |
| App is running in emulator | `isEmulator()`                     | `boolean` e.g. true                                                                           | if app is running in emulator return true                                                                           |
| App is running on a tablet | `isTablet()`                       | `boolean` e.g. true                                                                           | if app is running on a tablet return true                                                                           |
| PIN or fingerprint set     | `isPinOrFingerprintSet()`          | `(callback: (isPinOrFingerprintSet: boolean) => void) => void`                                | Only supported in Android and iOS 9.0 and above                                                                     |
| API Level                  | `getAPILevel()`                    | `number` e.g. 25                                                                              | ANDROID ONLY - see [API Levels](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)|
| App Instance ID            | `getInstanceID()`                  | `string`                                                                                      | ANDROID ONLY - see https://developers.google.com/instance-id/                                                       |
| Phone Number               | `getPhoneNumber()`                 | `?string` e.g. "2348675309" or ""                                                             | Only supported in Android                                                                                           |
| First Install Time         | `getFirstInstallTime()`            | `number` e.g. 1505607068808                                                                   | Only supported in Android                                                                                           |
| Last Install Time          | `getLastUpdateTime()`              | `number` e.g. 1505607068808                                                                   | Only supported in Android                                                                                           |
| 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"                                                                      |                                                                                                                     |
| Total Memory               | `getTotalMemory()`                 | `number` e.g. 1995018240                                                                      | Total amount of memory on the device                                                                               |
| Max Memory                 | `getMaxMemory()`                   | `number` e.g. 268435456                                                                       | ANDROID ONLY - see https://developer.android.com/reference/java/lang/Runtime.html#maxMemory()                       |
| App Name                   | `getApplicationName()`             | Learnium Mobile                                                                               |                                                                                                                  |


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
+118 −0

File changed.

Preview size limit exceeded, changes collapsed.

+64 −15
Original line number Diff line number Diff line
@@ -8,32 +8,45 @@

#import "RNDeviceInfo.h"
#import "DeviceUID.h"
#if !(TARGET_OS_TV)
#import <LocalAuthentication/LocalAuthentication.h>
#endif

@interface RNDeviceInfo()

@property (nonatomic) bool isEmulator;
@end

@import CoreTelephony;

@implementation RNDeviceInfo
{

}
@synthesize isEmulator;

RCT_EXPORT_MODULE()
RCT_EXPORT_MODULE(RNDeviceInfo)

- (dispatch_queue_t)methodQueue
+ (BOOL)requiresMainQueueSetup
{
    return dispatch_get_main_queue();
   return YES;
}


- (NSString*) deviceId
{
    struct utsname systemInfo;

    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine
    NSString* deviceId = [NSString stringWithCString:systemInfo.machine
                                            encoding:NSUTF8StringEncoding];

    if ([deviceId isEqualToString:@"i386"] || [deviceId isEqualToString:@"x86_64"] ) {
        deviceId = [NSString stringWithFormat:@"%s", getenv("SIMULATOR_MODEL_IDENTIFIER")];
        self.isEmulator = YES;
    } else {
        self.isEmulator = NO;
    }

    return deviceId;
}

- (NSString*) deviceName
@@ -42,9 +55,7 @@ RCT_EXPORT_MODULE()

    if (!deviceNamesByCode) {

        deviceNamesByCode = @{@"i386"      :@"Simulator",
                              @"x86_64"    :@"Simulator",
                              @"iPod1,1"   :@"iPod Touch",      // (Original)
        deviceNamesByCode = @{@"iPod1,1"   :@"iPod Touch",      // (Original)
                              @"iPod2,1"   :@"iPod Touch",      // (Second Generation)
                              @"iPod3,1"   :@"iPod Touch",      // (Third Generation)
                              @"iPod4,1"   :@"iPod Touch",      // (Fourth Generation)
@@ -86,6 +97,12 @@ RCT_EXPORT_MODULE()
                              @"iPhone9,3" :@"iPhone 7",        // (model A1778 | Global)
                              @"iPhone9,2" :@"iPhone 7 Plus",   // (model A1661 | CDMA)
                              @"iPhone9,4" :@"iPhone 7 Plus",   // (model A1784 | Global)
                              @"iPhone10,3":@"iPhone X",        // (model A1865, A1902)
                              @"iPhone10,6":@"iPhone X",        // (model A1901)
                              @"iPhone10,1":@"iPhone 8",        // (model A1863, A1906, A1907)
                              @"iPhone10,4":@"iPhone 8",        // (model A1905)
                              @"iPhone10,2":@"iPhone 8 Plus",   // (model A1864, A1898, A1899)
                              @"iPhone10,5":@"iPhone 8 Plus",   // (model A1897)
                              @"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)
@@ -103,10 +120,15 @@ RCT_EXPORT_MODULE()
                              @"iPad6,4"   :@"iPad Pro 9.7-inch",// iPad Pro 9.7-inch
                              @"iPad6,7"   :@"iPad Pro 12.9-inch",// iPad Pro 12.9-inch
                              @"iPad6,8"   :@"iPad Pro 12.9-inch",// iPad Pro 12.9-inch
                              @"iPad7,1"   :@"iPad Pro 12.9-inch",// 2nd Generation iPad Pro 12.5-inch - Wifi
                              @"iPad7,2"   :@"iPad Pro 12.9-inch",// 2nd Generation iPad Pro 12.5-inch - Cellular
                              @"iPad7,3"   :@"iPad Pro 10.5-inch",// iPad Pro 12.5-inch - Wifi
                              @"iPad7,4"   :@"iPad Pro 10.5-inch",// iPad Pro 12.5-inch - Cellular
                              @"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)
                              @"AppleTV6,2":@"Apple TV 4K",     // Apple TV 4K
                              };
    }

@@ -124,15 +146,29 @@ RCT_EXPORT_MODULE()
        else if([self.deviceId rangeOfString:@"iPhone"].location != NSNotFound){
            deviceName = @"iPhone";
        }
        else if([self.deviceId rangeOfString:@"AppleTV"].location != NSNotFound){
            deviceName = @"Apple TV";
        }
    }

    return deviceName;
}

- (NSString *) carrier
{
    CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [netinfo subscriberCellularProvider];
    return carrier.carrierName;
}

- (NSString*) userAgent
{
#if TARGET_OS_TV
    return @"not available";
#else
    UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
    return [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
#endif
}

- (NSString*) deviceLocale
@@ -153,14 +189,19 @@ RCT_EXPORT_MODULE()
  return currentTimeZone.name;
}

- (bool) isEmulator
- (bool) isTablet
{
  return [self.deviceName isEqual: @"Simulator"];
  return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
}

- (bool) isTablet
- (bool) is24Hour
{
  return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
    NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
    return ([format rangeOfString:@"a"].location == NSNotFound);
}

- (unsigned long long) totalMemory {
  return [NSProcessInfo processInfo].physicalMemory;
}

- (NSDictionary *)constantsToExport
@@ -172,6 +213,7 @@ RCT_EXPORT_MODULE()
    return @{
             @"systemName": currentDevice.systemName,
             @"systemVersion": currentDevice.systemVersion,
             @"apiLevel": @"not available",
             @"model": self.deviceName,
             @"brand": @"Apple",
             @"deviceId": self.deviceId,
@@ -184,17 +226,24 @@ 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),
             @"isTablet": @(self.isTablet),
             @"is24Hour": @(self.is24Hour),
             @"totalMemory": @(self.totalMemory)
             };
}

RCT_EXPORT_METHOD(isPinOrFingerprintSet:(RCTResponseSenderBlock)callback)
{
  #if TARGET_OS_TV
    BOOL isPinOrFingerprintSet = false;
  #else
    LAContext *context = [[LAContext alloc] init];
    BOOL isPinOrFingerprintSet = ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]);
  #endif
    callback(@[[NSNumber numberWithBool:isPinOrFingerprintSet]]);
}

+74 −7

File changed.

Preview size limit exceeded, changes collapsed.

Loading