AppVersion


#1

I need to get app version but I have the following problem:

typescript: C:/projects/ionic/flannery/node_modules/@ionic-native/app-version/index.d.ts, line: 25

Type 'any' is not a constructor function type.

      L25:  export declare class AppVersion extends IonicNativePlugin {

My codes:

ionic client
ionic plugin add cordova-plugin-app-version

app.module.ts

import { AppVersion } from '@ionic-native/app-version';
providers: [... AppVersion ... ]

mypage.ts

import { AppVersion } from '@ionic-native/app-version';
 AppVersion.getVersionNumber().then((s) => {
            console.log('ver', s);

        });

Cold you please helpme?

Thanks


#2

Have a look at the Usage example here:
https://ionicframework.com/docs/native/app-version/
You are missing it in the constructor and are using it wrong.


#3

Yes, I followed this page but I have a problem with my dependencies.

When I exec “npm install --save @ionic-native/app-version” I receive this WARN:

npm WARN @ionic-native/app-version@3.7.0 requires a peer of @ionic-native/core@^3.6.0 but none was installed.

My package.json:

  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic-native/app-version": "^3.7.0",
    "@ionic/storage": "2.0.1",
    "com-sarriaroman-photoviewer": "^1.1.10",
    "cordova-android": "^6.2.3",
    "cordova-ios": "^4.4.0",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-whitelist": "^1.3.2",
    "cordova-sqlite-storage": "~2.0.3",
    "ionic-angular": "2.2.0",
    "ionic-img-viewer": "^1.3.4",
    "ionic-native": "2.4.1",
    "ionicons": "3.0.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^1.3.7",
    "typescript": "2.0.9"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "description": "",
  "cordova": {
    "plugins": {
      "com-sarriaroman-photoviewer": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-app-version": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }

#4

You need to update your ionic native core version.

Remove the "ionic-native" line from your package.json, remove your node_modules folder, then run npm install @ionic-native/core --save.


#5

I done but when run my app I receive another error:

Runtime Error
Cannot find module "ionic-native"

I replaced my import
import {StatusBar, Splashscreen} from 'ionic-native';

with:
import {StatusBar, Splashscreen} from '@ionic-native';

but I didn’t solve the problem


#6

Solved the build

$ ionic plugin add --save cordova-plugin-statusbar
$ npm install --save @ionic-native/status-bar
$ ionic plugin add --save cordova-plugin-splashscreen
$ npm install --save @ionic-native/splash-screen
``

import { StatusBar } from ‘@ionic-native/status-bar’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;


But now I receive:
`Uncaught (in promise): cordova_not_available`

AppVersion.getVersionNumber().then((s) => {
this.versionNumber = s;
})


#7

here the solution: Ionic2 RC4 AppVersion error


#8

Then you didn’t post your code correctly before - and that is the only thing we can work off here.

But great that you got it to work.