fix(ios): Utils.openFile (#8914)

closes https://github.com/NativeScript/NativeScript/issues/8913
This commit is contained in:
Nathan Walker
2020-09-29 08:18:04 -07:00
committed by GitHub
parent 65b1cdbae0
commit 647926ee28
3 changed files with 33 additions and 27 deletions

View File

@ -11,7 +11,7 @@ export function openFile(filePath: string): boolean {
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
controller.delegate = <UIDocumentInteractionControllerDelegate>new iOSNativeHelper.UIDocumentInteractionControllerDelegateImpl();
controller.delegate = iOSNativeHelper.createUIDocumentInteractionControllerDelegate();
return controller.presentPreviewAnimated(true);
} catch (e) {

View File

@ -168,7 +168,10 @@ export namespace iOSNativeHelper {
*/
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.

View File

@ -14,7 +14,7 @@ function openFileAtRootModule(filePath: string): boolean {
let path = iOSNativeHelper.isRealDevice() ? filePath.replace('~', appPath) : filePath;
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
controller.delegate = new iOSNativeHelper.UIDocumentInteractionControllerDelegateImpl();
controller.delegate = iOSNativeHelper.createUIDocumentInteractionControllerDelegate();
return controller.presentPreviewAnimated(true);
} catch (e) {
@ -127,8 +127,9 @@ export namespace iOSNativeHelper {
return transform;
}
export function createUIDocumentInteractionControllerDelegate(): NSObject {
@NativeClass
export class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
public getViewController(): UIViewController {
@ -149,6 +150,8 @@ export namespace iOSNativeHelper {
return this.getViewController().view.frame;
}
}
return new UIDocumentInteractionControllerDelegateImpl();
}
export function isRealDevice() {
try {