現(xiàn)象描述
快應用部分接口不支持海外使用,例如service.share,如何在不影響國內版本使用的情況下,在海外屏蔽不支持的代碼?
問題分析
調用device.getCountryCode接口判斷當前快應用中心華為帳號的countryCode,如果是CN,則可以使用對應的接口。以service.share為例。
解決方法
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