const ua = navigator.userAgent.toLowerCase();

//微信小程序、微信公众号H5、浏览器、app环境
getENVIR: () => {
  const isWeixin = ua.indexOf('micromessenger') !== -1;
  const isInApp = /(^|;\s)app\//.test(ua);
  if (isWeixin) {
    if ((window as any).__wxjs_environment === 'miniprogram') {
      return 'wxapp';
    } else {
      return 'wxh5';
    }
  } else {
    if (!isInApp) {
      return 'browser';
    } else {
      return 'app';
    }
  }
},


//终端判断:是否是IOS

checkIfIOS: () => {
  return ua.match(/(iphone|ipod|ipad);?/i);
},

//终端判断:是否是Android

checkIfAndroid: () => {
  return ua.match(/android|adr/i);
},

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐