mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(ios): Utils.openFile (#8914)
closes https://github.com/NativeScript/NativeScript/issues/8913
This commit is contained in:
@ -11,7 +11,7 @@ export function openFile(filePath: string): boolean {
|
|||||||
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
|
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
|
||||||
|
|
||||||
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
|
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
|
||||||
controller.delegate = <UIDocumentInteractionControllerDelegate>new iOSNativeHelper.UIDocumentInteractionControllerDelegateImpl();
|
controller.delegate = iOSNativeHelper.createUIDocumentInteractionControllerDelegate();
|
||||||
|
|
||||||
return controller.presentPreviewAnimated(true);
|
return controller.presentPreviewAnimated(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
5
packages/core/utils/native-helper.d.ts
vendored
5
packages/core/utils/native-helper.d.ts
vendored
@ -168,7 +168,10 @@ export namespace iOSNativeHelper {
|
|||||||
*/
|
*/
|
||||||
export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any; /* CATransform3D*/
|
export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any; /* CATransform3D*/
|
||||||
|
|
||||||
export class UIDocumentInteractionControllerDelegateImpl {}
|
/**
|
||||||
|
* 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.
|
* Checks whether the application is running on real device and not on simulator.
|
||||||
|
@ -14,7 +14,7 @@ function openFileAtRootModule(filePath: string): boolean {
|
|||||||
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
|
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
|
||||||
|
|
||||||
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
|
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
|
||||||
controller.delegate = new iOSNativeHelper.UIDocumentInteractionControllerDelegateImpl();
|
controller.delegate = iOSNativeHelper.createUIDocumentInteractionControllerDelegate();
|
||||||
|
|
||||||
return controller.presentPreviewAnimated(true);
|
return controller.presentPreviewAnimated(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -127,8 +127,9 @@ export namespace iOSNativeHelper {
|
|||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createUIDocumentInteractionControllerDelegate(): NSObject {
|
||||||
@NativeClass
|
@NativeClass
|
||||||
export class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
||||||
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
||||||
|
|
||||||
public getViewController(): UIViewController {
|
public getViewController(): UIViewController {
|
||||||
@ -149,6 +150,8 @@ export namespace iOSNativeHelper {
|
|||||||
return this.getViewController().view.frame;
|
return this.getViewController().view.frame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new UIDocumentInteractionControllerDelegateImpl();
|
||||||
|
}
|
||||||
|
|
||||||
export function isRealDevice() {
|
export function isRealDevice() {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user