AppGallery Connect:如何在不影響國內版本使用的前提下,屏蔽海外不支持的快應用接口

來源: 華為開發(fā)者論壇
作者:AppGallery Connect
時間:2020-12-24
17237
快應用部分接口不支持海外使用,例如service.share,如何在不影響國內版本使用的情況下,在海外屏蔽不支持的代碼?

現(xiàn)象描述

快應用部分接口不支持海外使用,例如service.share,如何在不影響國內版本使用的情況下,在海外屏蔽不支持的代碼?

問題分析

調用device.getCountryCode接口判斷當前快應用中心華為帳號的countryCode,如果是CN,則可以使用對應的接口。以service.share為例。

0900086000150224722.20201223145956.56190513035085396632227670081896.png

解決方法

app.ux代碼如下:

復制

data: {

  localeObject: ''

},

test() {

  device.getServiceCountryCode({

    success: function (ret) {

      this.localeObject = ret.serviceCountryCode

      console.log(ret.serviceCountryCode);

    },

    fail: function (erromsg, errocode) {

      this.localeObject = 'errocode:' + errocode + ',erromsg:' + erromsg

      console.log(erromsg, errocode);

    },

    complete: function () {

    }

  })

  return this.localeObject

}

頁面ux中調用service.share接口的代碼如下:

fastAppShare() {

  if (this.$app.$def.test()==='CN') {

    share.share({

      //此處為三方分享內容

    })

  }

}

建議與總結

device接口參考:

https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-api-device#h2-1589360178560-0

立即登錄,閱讀全文
版權說明:
本文內容來自于華為開發(fā)者論壇,本站不擁有所有權,不承擔相關法律責任。文章內容系作者個人觀點,不代表快出海對觀點贊同或支持。如有侵權,請聯(lián)系管理員(zzx@kchuhai.com)刪除!
個人VIP