快應用海外不支持一些接口,比如 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