首页 > 移动开发 > ANDROID > 教你使用一套代码解决出海问题
快应用海外不支持一些接口,比如 service.share ,怎么在代码里判断并屏蔽,又不影响国内版本的使用呢?
解决方法:
可以先判断下 当前快应用中心华为帐号的countryCode( 如何获取详见:https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-api-device#h2-1589360178560-0) ,如果是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({
//此处为三方分享内容
})
}
}
原文链接: https://developer.huawei.com/consumer/cn/forum/topic/0201411988307210395?fid=18
原作者: Mayism
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69970551/viewspace-2768732/ ,如需转载,请注明出处,否则将追究法律责任。