Ionic AppVersion getPackageName()返回undefined

时间:2018-05-03 17:21:01

标签: typescript ionic-framework ionic3

我试图在AppVersion plugin中使用getPackageName()函数,但它在iOS和Android上都返回undefined。是否有另一种方法可以访问Ionic中的应用程序包名称?

当前代码:

  this.platform.ready()
    .then((readySource) => {
       this.appVersion.getPackageName()
         .then(packageName => {
            alert(packageName)
            this.market.open(packageName)
         })
         .catch(error => {
            console.log(`Error getting app package name. Error: ${error}`)
         })
     })

包名称在config.xml文件中定义,如下所示:

<widget android-packageName="com.company.appId" id="io.ionic.starter" ios-CFBundleIdentifier="com.company.iosAppId" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

1 个答案:

答案 0 :(得分:0)

尝试以下

constructor(public navCtrl: NavController, public plt: Platform) {
    this.plt.ready().then((readySource)=>{
      this.packageName = AppVersion.getPackageName();
   })
}