如何使用cordova-checkAppUpdate

时间:2019-02-22 12:22:55

标签: cordova ionic-framework

现在我正在使用IONIC3。我面临以下问题:

  1. 当我尝试获取UID.imei时,它没有给出IMEI。
  2. 即使我在更新URL上上传了更高版本的应用,我的应用也没有更新。
  3. 我正在更改config.xml中的版本,如下所示-
  4. 我的移动应用程序也未在设备上显示Google添加。
<widget id="io.ionic.starter" version="4.0.0" versionCode="40000" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

我的App.component.ts如下-

import {Component, ViewChild} from '@angular/core';
import {Nav, Platform, AlertController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {AuthService} from '../providers/auth-service';
import {TranslateService} from '@ngx-translate/core';
import { AppUpdate } from '@ionic-native/app-update/ngx';
import { AppVersion } from '@ionic-native/app-version/ngx';

@Component({
  templateUrl: 'app.html'
})

export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = 'ProfilePage';

  pages: Array<{title: string, component: any, icon:string, method?: any}>;

  constructor(
    public alertCtrl:AlertController,
    public appVersion: AppVersion,
    public appUpdate:AppUpdate,
    public platform: Platform,
    public statusBar: StatusBar,
    public splashScreen: SplashScreen,
    public authService: AuthService,
    translate: TranslateService) {

    this.initializeApp();

    translate.setDefaultLang('en');
    var versionCode = appVersion;
    // used for an example of ngFor and navigation
    this.pages = [
      {title: 'PROFILE', component: 'ProfilePage',icon:'person'},
      {title: 'MAP', component: 'MapPage',icon:'map'},
      {title: 'MY VISITS', component: 'MyvisitsPage',icon:'flag'},      
      //{title: 'SUBMIT OTP', component: 'SubmitotpPage',icon:'cell'},
      {title: 'page.logout', component: 'LoginPage', method: 'logout',icon:'exit'}
    ]; 
  }

  initializeApp() {
    this.appVersion.getVersionCode();
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.Update();
      this.statusBar.styleDefault();
      this.splashScreen.hide();

    });
  }

  Update(){
    const updateUrl = 'https://example.com/tos/rmup.xml';
    this.appUpdate
         .checkAppUpdate(updateUrl)
         .then(() => {this.present('Update Available'); })
         .catch(err=>{this.present(err);});
  }

  openPage(page) {

    if (page.method && page.method === 'logout') {
      this.authService.logout();
    } 

    this.nav.setRoot(page.component);
  }  


  present(mess:any){
    let alert = this.alertCtrl.create({
      message:mess,
      buttons: [
        {
          text: 'OK',
          role: 'ok',
          handler: data => {
            console.log('OK clicked');
          }
        }
      ]
    });

    alert.present();
  }
}

和我的profile.ts如下-

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, MenuController,AlertController,ToastController } from 'ionic-angular';
import {ProtectedPage} from '../protected-page/protected-page';
import{ JwtHelper, tokenNotExpired} from 'angular2-jwt';
import {Storage} from '@ionic/storage';
import {UserModel} from '../../models/user.model';
import{VisitService} from '../../providers/visit-service';
import{Visit} from '../../models/visit.interface';
import { LocationAccuracy } from '@ionic-native/location-accuracy';
import { Diagnostic } from '@ionic-native/diagnostic';
import { AdMobFree, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig } from '@ionic-native/admob-free';
import { Auth1Provider } from '../../providers/auth1-service';
import { AuthService } from '../../providers/auth-service';
import { AppUpdate } from '@ionic-native/app-update/ngx';
import { AppVersion } from '@ionic-native/app-version/ngx';
import { Device } from '@ionic-native/device/ngx';
import { Uid } from '@ionic-native/uid';
import { AndroidPermissions } from '@ionic-native/android-permissions';

@IonicPage()
@Component({
  selector: 'page-profile-page',
  templateUrl: 'profile-page.html',
})
export class ProfilePage extends ProtectedPage {
  public MESSAGE = [];
  public user: UserModel;
  visit = {} as Visit;

  constructor(private androidPermissions: AndroidPermissions,
    public toastCtrl: ToastController,
    public device: Device,
    private app: AppVersion,
    public auth: AuthService,
    public helper: JwtHelper,
    private locationAccuracy: LocationAccuracy,
    public admob: AdMobFree,
    private diagnostic: Diagnostic,
    private alertCtrl: AlertController,
    public navCtrl: NavController,
    public navParams: NavParams,
    public menuCtrl: MenuController,
    public visitService: VisitService,
    public uid: Uid,
    public storage: Storage) {

    super(auth, helper, navCtrl, navParams, storage);
    this.storage.get('user').then(user => {
      this.user = JSON.parse(user);
      console.log(this.user);
    });
  }

  ionViewDidLoad() {
    this.menuCtrl.enable(true);
  }

  async getImei() {
    const { hasPermission } = await this.androidPermissions.checkPermission(
      this.androidPermissions.PERMISSION.READ_PHONE_STATE
    );

    if (!hasPermission) {
      const result = await this.androidPermissions.requestPermission(
        this.androidPermissions.PERMISSION.READ_PHONE_STATE
      );

      if (!result.hasPermission) {
        throw new Error('Permissions required');
      }

      // ok, a user gave us permission, we can get him identifiers after restart app
      return;
    }

    // return this.uid.IMEI
    this.present(this.uid.IMEI);
    this.showBanner();
  }

  getPermission() {
    this.diagnostic
        .getPermissionAuthorizationStatus(this.diagnostic.permission.ACCESS_FINE_LOCATION)
        .then((status) => {
          //console.log(`AuthorizationStatus`);
          this.present(status);
          console.log(status);
          if (status != this.diagnostic.permissionStatus.GRANTED) {
            this.diagnostic
                .requestRuntimePermission(this.diagnostic.permission.ACCESS_FINE_LOCATION)
                .then((data) => {
                  // console.log(`getCameraAuthorizationStatus`);
                  this.present(data)
                  console.log(data);
                })
          } else {
            this.present('You Already Have Permission');
            //console.log("We have the permission");
          }
        }, (statusError) => {
          this.present(statusError)
        });
  }

  locationaccuracy() {
    this.locationAccuracy
        .canRequest()
        .then((canRequest: boolean) => {
          if (canRequest) {
            // the accuracy option will be ignored by iOS
            this.locationAccuracy
                .request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY)
                .then(() => {
                  this.present('Request sucessfull');
                },
                error => {
                  console.log('Error requesting location permissions', error)
                  this.present(error);
                });
          }
        });
  }

  present(mess: any) {
    let alert = this.alertCtrl.create({
      message: mess,
      buttons: [{
          text: 'OK',
          role: 'ok',
          handler: data => {
            console.log('OK clicked');
          }
        }
      ]
    });

    alert.present();
  }

  showBanner() {
    let bannerConfig: AdMobFreeBannerConfig = {
      isTesting: false, // Remove in production
      autoShow: true,
      id: 'ca-app-pub-1587639986409456~8324336092'
    };
    this.admob.banner.config(bannerConfig);
    this.admob.banner.prepare().then(() => {
      // success
    }).catch(e => console.log(e));
  }
}

我的rmup.xml

<update>
  <version>40001</version>
  <name> RM APP</name>
  <url>
    https://example.com/tos/android-debug.apk
  </url>
</update>

0 个答案:

没有答案