Commit 0021bb10 authored by 消失的旅人's avatar 消失的旅人

添加模拟器判断

parent 92c94a11
...@@ -148,6 +148,11 @@ RCT_EXPORT_MODULE() ...@@ -148,6 +148,11 @@ RCT_EXPORT_MODULE()
return currentTimeZone.name; return currentTimeZone.name;
} }
- (bool) isEmulator
{
return self.deviceName == @"Simulator";
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
...@@ -171,6 +176,7 @@ RCT_EXPORT_MODULE() ...@@ -171,6 +176,7 @@ RCT_EXPORT_MODULE()
@"systemManufacturer": @"Apple", @"systemManufacturer": @"Apple",
@"userAgent": self.userAgent, @"userAgent": self.userAgent,
@"timezone": self.timezone, @"timezone": self.timezone,
@"isEmulator": @(self.isEmulator),
}; };
} }
......
...@@ -52,6 +52,17 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -52,6 +52,17 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return current.getCountry(); return current.getCountry();
} }
private Boolean isEmulator() {
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| "google_sdk".equals(Build.PRODUCT);
}
@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>();
...@@ -94,6 +105,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -94,6 +105,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("bundleId", packageName); constants.put("bundleId", packageName);
constants.put("userAgent", System.getProperty("http.agent")); constants.put("userAgent", System.getProperty("http.agent"));
constants.put("timezone", TimeZone.getDefault().getID()); constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator());
return constants; return constants;
} }
} }
...@@ -56,4 +56,7 @@ module.exports = { ...@@ -56,4 +56,7 @@ module.exports = {
getTimezone: function() { getTimezone: function() {
return RNDeviceInfo.timezone; return RNDeviceInfo.timezone;
}, },
isEmulator: function() {
return RNDeviceInfo.isEmulator;
},
}; };
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