Commit aa93cd20 authored by wangqinghua's avatar wangqinghua

update

parent ec046c48
import { AppVersion } from '@ionic-native/app-version'; import {AppVersion} from '@ionic-native/app-version';
import { FileOpener } from '@ionic-native/file-opener'; import {FileOpener} from '@ionic-native/file-opener';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer'; import {FileTransfer, FileTransferObject} from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file'; import {File} from '@ionic-native/file';
import { Injectable } from '@angular/core'; import {Injectable} from '@angular/core';
import { AlertController } from 'ionic-angular'; import {AlertController} from 'ionic-angular';
import { AppService, AppGlobal } from './http.service' import {AppService, AppGlobal} from './http.service'
declare var cordova: any;
@Injectable() @Injectable()
export class AppUpdateService { export class AppUpdateService {
constructor(private appVersion: AppVersion, constructor(private appVersion: AppVersion,
private fileOpener: FileOpener, private fileOpener: FileOpener,
private fileTransfer: FileTransfer, private fileTransfer: FileTransfer,
private fileTransferObject: FileTransferObject, private fileTransferObject: FileTransferObject,
private file: File, private file: File,
private alertCtrl: AlertController, private alertCtrl: AlertController,
private appService: AppService, private appService: AppService,
) { ) {
} }
//检查是否需要软件更新 //检查是否需要软件更新
detectionUpgrade(apkUrl, allowChoose,newVersion) { detectionUpgrade(apkUrl, allowChoose, newVersion) {
if (allowChoose) { if (allowChoose) {
this.alertCtrl.create({ this.alertCtrl.create({
title: '升级提示', title: '升级提示',
subTitle: `发现最新版本v${newVersion},是否立即升级?`, subTitle: `发现最新版本v${newVersion},是否立即升级?`,
buttons: [ { buttons: [{
text: '确定', text: '确定',
handler: () => { handler: () => {
this.downloadApp(apkUrl); this.downloadApp(apkUrl);
...@@ -74,18 +71,20 @@ export class AppUpdateService { ...@@ -74,18 +71,20 @@ export class AppUpdateService {
const blob = xhr.response; const blob = xhr.response;
const fileName = 'temp.apk'; const fileName = 'temp.apk';
if (blob) { if (blob) {
let path = cordova.plugin.file.externalDataDirectory; let path = this.file.externalDataDirectory;
cordova.plugin.writeFile(path, fileName, blob, { console.log(path);
this.file.writeFile(path, fileName, blob, {
replace: true replace: true
}).then( }).then(
() => { () => {
cordova.plugin.fileOpener.open( console.log(`open`);
path + fileName, this.fileOpener.open(
'application/vnd.android.package-archive' path + fileName,
).catch((err) => { 'application/vnd.android.package-archive'
this.appService.alert('打开apk失败!'+err); ).catch((err) => {
}) this.appService.alert('打开apk失败!' + err);
}).catch((err) => { })
}).catch((err) => {
this.appService.alert('失败!'); this.appService.alert('失败!');
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment