mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
implemented new Util function isSimulatorOrEmulator
This commit is contained in:
3
packages/core/index.d.ts
vendored
3
packages/core/index.d.ts
vendored
@ -93,7 +93,7 @@ export type { InstrumentationMode, TimerInfo } from './profiling';
|
||||
export { encoding } from './text';
|
||||
export * from './trace';
|
||||
export * from './ui';
|
||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils';
|
||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils';
|
||||
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
||||
export declare const Utils: {
|
||||
GC: typeof GC;
|
||||
@ -111,6 +111,7 @@ export declare const Utils: {
|
||||
openFile: typeof openFile;
|
||||
openUrl: typeof openUrl;
|
||||
isRealDevice: typeof isRealDevice;
|
||||
isSimulatorOrEmulator: typeof isSimulatorOrEmulator;
|
||||
layout: typeof layout;
|
||||
android: typeof androidUtils;
|
||||
ad: typeof androidUtils;
|
||||
|
@ -110,7 +110,7 @@ export * from './trace';
|
||||
|
||||
export * from './ui';
|
||||
|
||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils';
|
||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils';
|
||||
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
||||
|
||||
export const Utils = {
|
||||
@ -131,6 +131,7 @@ export const Utils = {
|
||||
openFile,
|
||||
openUrl,
|
||||
isRealDevice,
|
||||
isSimulatorOrEmulator,
|
||||
|
||||
layout,
|
||||
android: androidUtils,
|
||||
|
@ -167,3 +167,7 @@ Please ensure you have your manifest correctly configured with the FileProvider.
|
||||
export function isRealDevice(): boolean {
|
||||
return ad.isRealDevice();
|
||||
}
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean {
|
||||
return ad.isSimulatorOrEmulator();
|
||||
}
|
||||
|
2
packages/core/utils/index.d.ts
vendored
2
packages/core/utils/index.d.ts
vendored
@ -286,3 +286,5 @@ export function eliminateDuplicates(arr: Array<any>): Array<any>;
|
||||
* Checks whether the application is running on real device and not on simulator/emulator.
|
||||
*/
|
||||
export function isRealDevice(): boolean;
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean;
|
||||
|
@ -47,4 +47,8 @@ export function isRealDevice(): boolean {
|
||||
return iOSNativeHelper.isRealDevice();
|
||||
}
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean {
|
||||
return iOSNativeHelper.isSimulatorOrEmulator();
|
||||
}
|
||||
|
||||
export const ad = 0;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { getNativeApplication, android as androidApp } from '../application';
|
||||
import { Trace } from '../trace';
|
||||
import { isNullOrUndefined } from './types';
|
||||
|
||||
// We are using "ad" here to avoid namespace collision with the global android object
|
||||
export namespace ad {
|
||||
@ -153,9 +154,17 @@ export namespace ad {
|
||||
|
||||
export function isRealDevice(): boolean {
|
||||
const fingerprint = android.os.Build.FINGERPRINT;
|
||||
|
||||
return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1);
|
||||
}
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean {
|
||||
const fingerprint = android.os.Build.FINGERPRINT;
|
||||
if (isNullOrUndefined(fingerprint)) {
|
||||
return true;
|
||||
} else {
|
||||
return fingerprint.includes('vbox') || fingerprint.includes('generic');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const iOSNativeHelper = 0;
|
||||
|
10
packages/core/utils/native-helper.d.ts
vendored
10
packages/core/utils/native-helper.d.ts
vendored
@ -88,6 +88,8 @@ export namespace ad {
|
||||
* Checks whether the application is running on real device and not on emulator.
|
||||
*/
|
||||
export function isRealDevice(): boolean;
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean;
|
||||
}
|
||||
/**
|
||||
* Module with ios specific utilities.
|
||||
@ -168,13 +170,15 @@ export namespace iOSNativeHelper {
|
||||
*/
|
||||
export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any; /* CATransform3D*/
|
||||
|
||||
/**
|
||||
* Create a UIDocumentInteractionControllerDelegate implementation for use with UIDocumentInteractionController
|
||||
*/
|
||||
/**
|
||||
* Create a UIDocumentInteractionControllerDelegate implementation for use with UIDocumentInteractionController
|
||||
*/
|
||||
export function createUIDocumentInteractionControllerDelegate(): any;
|
||||
|
||||
/**
|
||||
* Checks whether the application is running on real device and not on simulator.
|
||||
*/
|
||||
export function isRealDevice(): boolean;
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Trace } from '../trace';
|
||||
import { isNullOrUndefined } from './types';
|
||||
|
||||
declare let UIImagePickerControllerSourceType: any;
|
||||
|
||||
@ -125,33 +126,33 @@ export namespace iOSNativeHelper {
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
export function createUIDocumentInteractionControllerDelegate(): NSObject {
|
||||
@NativeClass
|
||||
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
||||
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
||||
|
||||
public getViewController(): UIViewController {
|
||||
const app = UIApplication.sharedApplication;
|
||||
|
||||
return app.keyWindow.rootViewController;
|
||||
}
|
||||
|
||||
public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) {
|
||||
return this.getViewController();
|
||||
}
|
||||
|
||||
public documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController) {
|
||||
return this.getViewController().view;
|
||||
}
|
||||
|
||||
public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect {
|
||||
return this.getViewController().view.frame;
|
||||
}
|
||||
}
|
||||
return new UIDocumentInteractionControllerDelegateImpl();
|
||||
}
|
||||
}
|
||||
|
||||
export function createUIDocumentInteractionControllerDelegate(): NSObject {
|
||||
@NativeClass
|
||||
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
||||
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
||||
|
||||
public getViewController(): UIViewController {
|
||||
const app = UIApplication.sharedApplication;
|
||||
|
||||
return app.keyWindow.rootViewController;
|
||||
}
|
||||
|
||||
public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) {
|
||||
return this.getViewController();
|
||||
}
|
||||
|
||||
public documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController) {
|
||||
return this.getViewController().view;
|
||||
}
|
||||
|
||||
public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect {
|
||||
return this.getViewController().view.frame;
|
||||
}
|
||||
}
|
||||
return new UIDocumentInteractionControllerDelegateImpl();
|
||||
}
|
||||
|
||||
export function isRealDevice() {
|
||||
try {
|
||||
@ -164,4 +165,9 @@ export namespace iOSNativeHelper {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function isSimulatorOrEmulator(): boolean {
|
||||
const realDevice = isRealDevice();
|
||||
return isNullOrUndefined(realDevice);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user