Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nativescript-core/utils/native-helper.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,10 @@ export module ad {
return result;
}
}

export function isRealDevice(): boolean {
const fingerprint = android.os.Build.FINGERPRINT;

return fingerprint != null && (fingerprint.indexOf("vbox") > -1 || fingerprint.indexOf("generic") > -1);
}
}
12 changes: 11 additions & 1 deletion nativescript-core/utils/native-helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export module ad {
*/
export function getPaletteColor(name: string, context: any /* android.content.Context */): number;
}

/**
* Checks whether the application is running on real device and not on emulator.
*/
export function isRealDevice(): boolean;
}
/**
* Module with ios specific utilities.
Expand Down Expand Up @@ -156,7 +161,7 @@ export module ios {
export function getVisibleViewController(rootViewController: any/* UIViewController*/): any/* UIViewController*/;

/**
*
*
* @param transform Applies a rotation transform over X,Y and Z axis
* @param x Rotation over X axis in degrees
* @param y Rotation over Y axis in degrees
Expand All @@ -165,4 +170,9 @@ export module ios {
export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any /* CATransform3D*/;

export class UIDocumentInteractionControllerDelegateImpl { }

/**
* Checks whether the application is running on real device and not on simulator.
*/
export function isRealDevice(): boolean;
}
17 changes: 15 additions & 2 deletions nativescript-core/utils/native-helper.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
categories as traceCategories,
write as traceWrite
} from "../trace";
import { isRealDevice } from "./utils";

declare var UIImagePickerControllerSourceType: any;

const radToDeg = Math.PI / 180;

Expand All @@ -15,7 +16,7 @@ function isOrientationLandscape(orientation: number) {
function openFileAtRootModule(filePath: string): boolean {
try {
const appPath = ios.getCurrentAppPath();
let path = isRealDevice() ? filePath.replace("~", appPath) : filePath;
let path = ios.isRealDevice() ? filePath.replace("~", appPath) : filePath;

const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
controller.delegate = new ios.UIDocumentInteractionControllerDelegateImpl();
Expand Down Expand Up @@ -154,4 +155,16 @@ export module ios {
return this.getViewController().view.frame;
}
}

export function isRealDevice() {
try {
// https://stackoverflow.com/a/5093092/4936697
const sourceType = UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera;
const mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(sourceType);

return mediaTypes;
} catch (e) {
return true;
}
}
}
5 changes: 2 additions & 3 deletions nativescript-core/utils/utils.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ Please ensure you have your manifest correctly configured with the FileProvider.
}
}

export function isRealDevice() {
const fingerprint = android.os.Build.FINGERPRINT;
this._isSimulator = fingerprint != null && (fingerprint.indexOf("vbox") > -1 || fingerprint.indexOf("generic") > -1);
export function isRealDevice(): boolean {
return ad.isRealDevice();
}
2 changes: 1 addition & 1 deletion nativescript-core/utils/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,6 @@ export function hasDuplicates(arr: Array<any>): boolean;
export function eliminateDuplicates(arr: Array<any>): Array<any>;

/**
* Checks whether the application is running on real device or simulator/emulator.
* Checks whether the application is running on real device and not on simulator/emulator.
*/
export function isRealDevice(): boolean;
16 changes: 3 additions & 13 deletions nativescript-core/utils/utils.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import {
export { ios };
export * from "./utils-common";

declare var UIImagePickerControllerSourceType: any;

export function openFile(filePath: string): boolean {
try {
const appPath = ios.getCurrentAppPath();
const path = filePath.replace("~", appPath);
let path = ios.isRealDevice() ? filePath.replace("~", appPath) : filePath;

const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
controller.delegate = <UIDocumentInteractionControllerDelegate>new ios.UIDocumentInteractionControllerDelegateImpl();
Expand Down Expand Up @@ -48,14 +46,6 @@ export function openUrl(location: string): boolean {
return false;
}

export function isRealDevice() {
try {
// https://stackoverflow.com/a/5093092/4936697
const sourceType = UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera;
const mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(sourceType);

return mediaTypes;
} catch (e) {
return true;
}
export function isRealDevice(): boolean {
return ios.isRealDevice();
}