我正在浏览器中运行一个使用capacitor的ionic 5应用程序,并且我正在尝试使用文件传输功能。我遵循文档https://ionicframework.com/docs/native/file-transfer并使用电容器配置我的应用程序。因此运行:
npm install cordova-plugin-file-transfer
npm install @ionic-native/file-transfer
ionic cap sync在我的app.module中,我注册了提供者:
import { FileTransfer } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file/ngx';
...
providers: [
StatusBar,
SplashScreen,
...
FileTransfer,
File
],请注意,我还安装了本机文件包,因此总共有以下4个新包:
"@ionic-native/file": "^5.27.0",
"@ionic-native/file-transfer": "^5.27.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-transfer": "^1.7.1",我在组件中的代码是:
import { Input, Component } from '@angular/core';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file/ngx';
@Component({
selector: 'app-order-detail-order-card',
templateUrl: './order-detail-order-card.page.html'
})
export class OrderDetailOrderCardPage {
@Input() pdfUrl: string;
@Input() orderCardId: string;
constructor(private transfer: FileTransfer, private file: File) { }
public downloadFile(): void {
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(this.pdfUrl, this.file.applicationDirectory + `${orderCardId}.pdf`).then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
}当我在浏览器中运行应用程序时,我收到以下警告,并且我不确定文件是否应该加载到某个地方?
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator即使我没有得到文件,我也希望看到“下载完成”的消息。我不是很清楚,我是否必须在我的应用程序中配置其他东西才能在本地运行它,或者我必须仅在模拟器或设备本身中使用此功能。
还需要配置什么才能使其正常工作?
发布于 2021-05-26 21:20:40
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator这意味着你使用的浏览器模拟器没有任何闪屏,你可以完全忽略这个警告(你不会得到它使用模拟器或真实的设备)。
您还应该粘贴该页面的html部分,因为下载可能因为url不完整而无法启动,并且它不会继续使用"then()“
也许我错了,但这是可能的。
https://stackoverflow.com/questions/63177906
复制相似问题