← 输入框|github.com|刷新
Skip to content

There is no Utility to determine whether current execution is on a simulator or emulator #9064

Description

@alexziskind1

Is your feature request related to a problem? Please describe.
The current function isRealDevice does not work properly on Android, and returns data on iOS instead of a boolean.
There are other relying functions that call isRealDevice.

Describe the solution you'd like
Instead of introducing a breaking change, create a new isSimulatorOrEmulator function that actually returns a boolean.

Describe alternatives you've considered
Changing the isRealDevice function. This would cause breaking changes.

Activity

  1. NathanaelA commented on Nov 27, 2020

    @NathanaelA
  2. cjohn001 commented on Nov 28, 2020

    @cjohn001

    Hello together,
    I use the following code snippet to detect if I am on a simulator. So far I have not found any issues with it, maybe it helps you:

    export class DeviceInfo {
    	static deviceId(): string {
    		let deviceId = '';
    		if (global.isIOS) {
    			const systemInfo = new interop.Reference<utsname>();
    			uname(systemInfo);
    			deviceId = NSString.stringWithUTF8String(systemInfo.value.machine).toString();
    		} else {
    			deviceId = android.os.Build.BOARD;
    			if (!(deviceId && !deviceId.toLocaleLowerCase().includes('unknown'))) {
    				deviceId = android.os.Build.SERIAL;
    			}
    		}
    		return deviceId;
    	}
    	static isEmulator(): boolean {
    		if (global.isIOS) {
    			return DeviceInfo.deviceId() === 'i386' || DeviceInfo.deviceId() === 'x86_64';
    		} else {
    			const Build = android.os.Build;
    			return (
    				Build.FINGERPRINT.startsWith('generic') ||
    				Build.FINGERPRINT.startsWith('unknown') ||
    				Build.MODEL.includes('google_sdk') ||
    				Build.MODEL.includes('Emulator') ||
    				Build.MODEL.includes('Android SDK built for x86') ||
    				Build.MANUFACTURER.includes('Genymotion') ||
    				(Build.BRAND.startsWith('generic') && Build.DEVICE.startsWith('generic')) ||
    				'google_sdk' === Build.PRODUCT
    			);
    		}
    	}
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions