关于IONIC2 无法下载更新的问题。? 400 报错
从 my.oschina.net/u/24110/blog/750970 抄来的,有点问题但是又不知道是什么地方出错。
代码如下
import { Component } from '@angular/core';
import {AppVersion} from 'ionic-native';
import { NavController } from 'ionic-angular';
import {Transfer, FileOpener} from "ionic-native";
import { LoadingController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { File } from 'ionic-native';
/*
Generated class for the NewPage page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-new-page',
templateUrl: 'new-page.html'
})
export class NewPagePage {
constructor(public loadingCtrl: LoadingController) {}
upgradeApp() {
const fileTransfer = new Transfer();
let uploading = this.loadingCtrl.create({
content: "zhengzaixiazai...",
dismissOnPageChange: false
});
var url = "http://210.21.199.68:8080/web/data/commu.apk"; //可以从服务端获取更新APP的路径
var targetPath = "/sdcard/Download/commun.apk"; //APP下载存放的路径,可以使用cordova file插件进行相关配置
// var options = {};
uploading.present();
fileTransfer.onProgress((event) => {
//进度,这里使用文字显示下载百分比
// setTimeout(function () {
var downloadProgress = (event.loaded / event.total) * 100;
uploading.setContent("已经下载:" + Math.floor(downloadProgress) + "%");
if (downloadProgress > 99) {
uploading.destroy();
}
// },10000);
/* setTimeout(() => {
uploading.dismiss();
}, 10000);*/
});
//url为服务端地址
//targetPath为设备上的地址
fileTransfer.download(url, targetPath, true).then(
(result) => {
uploading.destroy();
FileOpener.open(targetPath, 'application/vnd.android.package-archive').then(
() => {
});
}
);
}
}
、
ionic-naive 也是2.2版本的。求大神指点!