mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(utils): work openFile in simulator (#8495)
* feat: open file in iOS simulator * feat: added isRealDevice util * feat: have in mind isRealDevice in utils.openFile refactor to avoid some circular dependencies Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
This commit is contained in:
@@ -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
nativescript-core/utils/native-helper.d.ts
vendored
12
nativescript-core/utils/native-helper.d.ts
vendored
@@ -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.
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
write as traceWrite
|
||||
} from "../trace";
|
||||
|
||||
declare var UIImagePickerControllerSourceType: any;
|
||||
|
||||
const radToDeg = Math.PI / 180;
|
||||
|
||||
function isOrientationLandscape(orientation: number) {
|
||||
@@ -14,7 +16,7 @@ function isOrientationLandscape(orientation: number) {
|
||||
function openFileAtRootModule(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 = new ios.UIDocumentInteractionControllerDelegateImpl();
|
||||
@@ -153,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,3 +182,7 @@ Please ensure you have your manifest correctly configured with the FileProvider.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isRealDevice(): boolean {
|
||||
return ad.isRealDevice();
|
||||
}
|
||||
|
||||
5
nativescript-core/utils/utils.d.ts
vendored
5
nativescript-core/utils/utils.d.ts
vendored
@@ -347,3 +347,8 @@ export function hasDuplicates(arr: Array<any>): boolean;
|
||||
* @param arr - The array.
|
||||
*/
|
||||
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;
|
||||
@@ -9,7 +9,7 @@ export * from "./utils-common";
|
||||
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();
|
||||
@@ -45,3 +45,7 @@ export function openUrl(location: string): boolean {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isRealDevice(): boolean {
|
||||
return ios.isRealDevice();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user