native-script-分享文件
将文件发送/分享到其他应用。
npm i --save native-script-分享文件

Nativescript Share File

将/分享文件到其他应用。

Android 意图, IOS InteractionController

.

安装

在您的应用中安装插件。

npm install nativescript-share-file

使用方法

信息:共享文件应在 documents 路径中。

    import { ShareFile } from 'nativescript-share-file';
import * as fs from 'tns-core-modules/file-system';

export class TestClass{

shareFile;
fileName;
documents;
path;
file;

constructor() {

this.fileName = 'text.txt';
this.documents = fs.knownFolders.documents();
this.path = fs.path.join(this.documents.path, this.fileName);
this.file = fs.File.fromPath(this.path);
this.shareFile = new ShareFile();

this.shareFile.open( {
path: this.path,
intentTitle: 'Open text file with:', // optional Android
rect: { // optional iPad
x: 110,
y: 110,
width: 0,
height: 0
},
options: true, // optional iOS
animated: true // optional iOS
});
}
}

参数

path

共享文件的路径。

String: 必填

intentTitle

Android 上的意图标题。

String: (可选) 默认: 打开文件:.

rect

用于 iPad 的视图定位。在 iPhone 上它总是显示在底部。

Object: (可选) 默认: {x: 0, y: 0, width: 0, height: 0 }.

options

显示 iOS 设备的附加打开选项。

Boolean: (可选) 默认: false.

animated

用于 iOS 设备的打开动画。

Boolean: (可选) 默认: false.