从离子开放市场失败

时间:2016-05-18 07:23:16

标签: android ionic-framework

我有这个离子应用程序,我根据操作系统放置代码打开浏览器并转到应用程序商店或谷歌播放。 对App Store的调用有效。 app store的字符串是:

market = 'https://itunes.apple.com/us/app/my_app_name/id12345';

而对于android来说是:

market = 'market://details?id=<package_name>';

打开浏览器的代码是:

cordova.InAppBrowser.open(market, '_blank', 'location=yes');

当我尝试在Android中打开时,会打开某种浏览器并显示消息:

"Web page not available. The webpage at market://details?id=my_app_id might be temporarly down ..."

在此之前,Google Play的字符串是您通常在浏览器中使用的字符串,即:

http://play.google.com/store/apps/details?id=<package_name>

在这种情况下,消息是关于更不支持谷歌播放呼叫的更加明智。它询问我是否要下载google play app。

我猜正确的方法是使用“市场”-prefix?但仍然不明白为什么它没有显示应用程序。

3 个答案:

答案 0 :(得分:2)

好,所以我研究了ios的“ cordova-plugin-market”源代码。这是appstore网址的构建方式:

NSString *url = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/%@", appId];

如果要从PC浏览器进行导航,这是url的外观:

https://itunes.apple.com/app/ id 333903271(例如,Twitter)

因此,如果您将此插件用于Ios,请考虑添加'id'前缀,而不要使用应用程序的Apple ID而不是捆绑包ID(程序包名称)。对于android,当然com.example.package就足够了

let appId;

if (this.platform.is("android")) {
  appId = "com.example.package"
} else {
  appId =  "id1234567"
}

this.market.open(appId).then(response => {
  console.debug(response);

}).catch(error => {
  console.warn(error);
});

}

答案 1 :(得分:0)

我补充说 cordova插件添加https://github.com/xmartlabs/cordova-plugin-market 然后它奏效了。

答案 2 :(得分:0)

import { InAppBrowserOptions, InAppBrowser } from '@ionic-native/in-app-browser';
import { Market } from "@ionic-native/market";
import { Platform } from "ionic-angular";

constructor(private market:Market, private inappBrowswer:InAppBrowser, 
private platform:Platform)
{
this.onUpdateNow();//Call the update function
}

onUpdateNow() {
    this.platform.ready().then(() => {
      if (this.platform.is("ios")) {
        //replace '310633997' with your iOS App ID
        this.openInAppStore('itms-apps://itunes.apple.com/app/310633997'); //call the openInAppStore
      } else if (this.platform.is("android")) {
        //replace 'com.whatsapp.saint' with your Android App ID
        this.market.open("com.whatsapp.saint").then(response => {
          console.log(response);
        }).catch(error => {
          console.log(error);
        });
      }
  });
}

openInAppStore(link) {
    let options: InAppBrowserOptions = {
      location: 'yes',//Or 'no' 
    };
    let target = "_blank";
    this.inappBrowswer.create(link, target, options);
  }