js调起android安卓与ios苹果方法 vue3.0 + ts

let shareSelect = (ev :any) => {
const u :any= navigator.userAgent;                 
const win :any = window
const windowsAndroid :any = win.android
const windowsWebkit :any = win.webkit
const isAndroid:any = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android安卓
const isiOS :any= !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios苹果
if (isAndroid) {
  let obj:any = {
    image:state.shareImage,
    title:state.shopInfo.shopName,
    description:state.shopInfo.address,
    }
    let params:any = JSON.stringify(obj)
    try {
      windowsAndroid.shareLinkContentToSession(params)//shareLinkContentToSession 为安卓定义的方法
} catch (e) { 
  console.log(e)       
} 
} else if (isiOS) {
 let obj:any = {
    image:state.shareImage,
    title:state.shopInfo.shopName,
        description:state.shopInfo.address
    }
let params :any= JSON.stringify(obj) 
    try { 
      windowsWebkit.messageHandlers.shareLinkContentToSession.postMessage(params)//shareLinkContentToSession 为ios定义的方法
    } catch (e) { 
      console.log(e) 
    } 
  }
}

 

posted @ 2021-09-18 15:09  骚楠  阅读(269)  评论(0编辑  收藏  举报