Commit 9887f878 authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #224 from douglasjunior/patch-1

Added device detection even when in an iOS emulator.
parents 40e1b51c 45463d87
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#import <LocalAuthentication/LocalAuthentication.h> #import <LocalAuthentication/LocalAuthentication.h>
@interface RNDeviceInfo() @interface RNDeviceInfo()
@property (nonatomic) bool isEmulator;
@end @end
@implementation RNDeviceInfo @implementation RNDeviceInfo
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
} }
@synthesize isEmulator;
RCT_EXPORT_MODULE() RCT_EXPORT_MODULE()
- (dispatch_queue_t)methodQueue - (dispatch_queue_t)methodQueue
...@@ -32,8 +34,17 @@ RCT_EXPORT_MODULE() ...@@ -32,8 +34,17 @@ RCT_EXPORT_MODULE()
uname(&systemInfo); uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine NSString* deviceId = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding]; 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 - (NSString*) deviceName
...@@ -42,9 +53,7 @@ RCT_EXPORT_MODULE() ...@@ -42,9 +53,7 @@ RCT_EXPORT_MODULE()
if (!deviceNamesByCode) { if (!deviceNamesByCode) {
deviceNamesByCode = @{@"i386" :@"Simulator", deviceNamesByCode = @{@"iPod1,1" :@"iPod Touch", // (Original)
@"x86_64" :@"Simulator",
@"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)
@"iPod4,1" :@"iPod Touch", // (Fourth Generation) @"iPod4,1" :@"iPod Touch", // (Fourth Generation)
...@@ -86,6 +95,9 @@ RCT_EXPORT_MODULE() ...@@ -86,6 +95,9 @@ RCT_EXPORT_MODULE()
@"iPhone9,3" :@"iPhone 7", // (model A1778 | Global) @"iPhone9,3" :@"iPhone 7", // (model A1778 | Global)
@"iPhone9,2" :@"iPhone 7 Plus", // (model A1661 | CDMA) @"iPhone9,2" :@"iPhone 7 Plus", // (model A1661 | CDMA)
@"iPhone9,4" :@"iPhone 7 Plus", // (model A1784 | Global) @"iPhone9,4" :@"iPhone 7 Plus", // (model A1784 | Global)
@"iPhone10,3":@"iPhone X", //
@"iPhone10,4":@"iPhone 8", //
@"iPhone10,5":@"iPhone 8 Plus", //
@"iPad4,1" :@"iPad Air", // 5th Generation iPad (iPad Air) - Wifi @"iPad4,1" :@"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2" :@"iPad Air", // 5th Generation iPad (iPad Air) - Cellular @"iPad4,2" :@"iPad Air", // 5th Generation iPad (iPad Air) - Cellular
@"iPad4,3" :@"iPad Air", // 5th Generation iPad (iPad Air) @"iPad4,3" :@"iPad Air", // 5th Generation iPad (iPad Air)
...@@ -153,11 +165,6 @@ RCT_EXPORT_MODULE() ...@@ -153,11 +165,6 @@ RCT_EXPORT_MODULE()
return currentTimeZone.name; return currentTimeZone.name;
} }
- (bool) isEmulator
{
return [self.deviceName isEqual: @"Simulator"];
}
- (bool) isTablet - (bool) isTablet
{ {
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad; return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
......
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