uniapp打开应用商店,并定位到具体的应用

1,284 阅读1分钟

uniapp中打开第三方应用

  • 使用launchApplication方法打开第三方应用
  • 以打开谷歌验证器为例
// #ifdef APP-PLUS
if (this.platform === 'ios') {
  // ios接收action,action是应用的schema
  plus.runtime.launchApplication({
    action: `googleauthenticator://`  // 谷歌验证器的schema
  }, err => {
    this.$u.toast(err)
  });
} else {
  // 安卓接收pname,pname是应用的包名
  plus.runtime.launchApplication({
    pname: 'com.google.android.apps.authenticator2' // 谷歌验证器的包名
  }, err => {
    this.$u.toast(err)
  });
}
// #endif

如何寻找一个 App 的 URL Schemes

ios打开appStore,并定位到对应的应用

  • 以谷歌验证器app为例
let appleId = 388497605 // 谷歌验证器的appid
// ios打开app store
plus.runtime.launchApplication({
  action: `itms-apps://itunes.apple.com/app/id${appleId}?mt=8`
}, err => {
  this.$u.toast(err)
});

如何查找ios应用的appid?

  1. 打开app store,进入应用详情,点击分享

  1. 拷贝链接,得到类似这样的链接:apps.apple.com/sg/app/mari…
  2. 其中:1293634699就是该应用的id

Android打开Google Play,并定位到应用详情

  • 这里需要使用openURL方法,其第三个参数可以接收一个应用包名:使用该应用打开url
  • 这里url设计,参考谷歌商店的文档:(需翻墙)链接到Google Play
// 通过谷歌商店打开谷歌验证器,id后面是应用的包名
const url = 'https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2'
plus.runtime.openURL(url, err => {
  this.$u.toast(err)
}, "com.android.vending"); // "com.android.vending"是谷歌商店的包名

如何查找谷歌商店应用的包名?

  1. 打开谷歌商店官网(需翻墙)Google Play

  1. 搜索,进入应用详情,此时网页的链接中就包含该应用的包名