import { Component,ViewChild } from '@angular/core';
import { Platform,AlertController,Content } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

// import { TabsPage } from '../pages/tabs/tabs';
import { LoginPage } from '../pages/login/login';
import { AppVersion } from '@ionic-native/app-version';
import { AppUpdateService } from '../service/appUpdateService';
import { Keyboard } from '@ionic-native/keyboard';
import { Badge } from '@ionic-native/badge';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Content) content: Content;

  rootPage:any = LoginPage;

  constructor(platform: Platform, 
    statusBar: StatusBar, 
    splashScreen: SplashScreen,
    alertCtrl: AlertController,
    keyboard:Keyboard,
    appUpdateService: AppUpdateService,
    appVersion: AppVersion,
    badge:Badge
  ) {
    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.
      statusBar.styleDefault();
      splashScreen.hide();
      //检测是否需要更新
      appVersion.getVersionNumber().then((version: string) => {
        appUpdateService.compariVersion().subscribe(data => {
          if (data.code == 200) {
            if (data.latestVersion != null && data.latestVersion != version) {
              appUpdateService.detectionUpgrade(data.androidDownload, true); //提示升级  
            }
          }
        });
      }).catch(err => {
        console.log('getVersionNumber:' + err);
      });
      //log角标数目显示
      badge.set(10);

    });
  }
}
