mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #1479 from NativeScript/openFile-for-ios
openFile add for iOS
This commit is contained in:
6
utils/utils.d.ts
vendored
6
utils/utils.d.ts
vendored
@@ -188,6 +188,12 @@
|
||||
* Gets the iOS device major version (for 8.1 will return 8).
|
||||
*/
|
||||
export var MajorVersion: number;
|
||||
|
||||
/**
|
||||
* Opens file with associated application.
|
||||
* @param filePath The file path.
|
||||
*/
|
||||
export function openFile(filePath: string): boolean
|
||||
}
|
||||
/**
|
||||
* An utility function that copies properties from source object to target object.
|
||||
|
||||
@@ -3,6 +3,7 @@ import common = require("./utils-common");
|
||||
import colorModule = require("color");
|
||||
import enums = require("ui/enums");
|
||||
import * as typesModule from "utils/types";
|
||||
import * as fsModule from "file-system";
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
@@ -200,6 +201,21 @@ export module ios {
|
||||
}
|
||||
|
||||
export var MajorVersion = NSString.stringWithString(UIDevice.currentDevice().systemVersion).intValue;
|
||||
|
||||
export function openFile(filePath: string): boolean {
|
||||
try {
|
||||
var fs: typeof fsModule = require("file-system");
|
||||
var path = filePath.replace("~", fs.knownFolders.currentApp().path)
|
||||
|
||||
var controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
|
||||
controller.delegate = new UIDocumentInteractionControllerDelegateImpl();
|
||||
return controller.presentPreviewAnimated(true);
|
||||
}
|
||||
catch (e) {
|
||||
console.error("Error in openFile", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function GC() {
|
||||
@@ -219,3 +235,24 @@ export function openUrl(location: string): boolean {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
||||
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
||||
|
||||
public getViewController() : UIViewController {
|
||||
var frame = require("ui/frame");
|
||||
return frame.topmost().currentPage.ios;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user