H 5原生アプリとインタラクティブノート

4471 ワード

目次
1. H5    APP  ;
2.   APP  H5  ;
3. H5    APP  ;
4. H5    APP

H 5ネイティブアプリの呼び出し方法
// name     (APP      )
// data         (  :     ,       ,         APP)

//         data   ,    window.App[name)](); 
//         data   ,  window.App[](data);
// IOS      data   ,  window.webkit.messageHandlers[name].postMessage(null);(IOS     ,   null)
//        data   , window.webkit.messageHandlers[name].postMessage(data);

//    APP      
//       ,      ,IOS   null
export const useNativeMethod = (name, data = null) => {
    if (state.Navigator.indexOf('Android') > -1 || state.Navigator.indexOf('Adr') > -1) {
        window.App[name](data);
    } else if (!!state.Navigator.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        window.webkit.messageHandlers[name].postMessage(data);
    }
}

オリジナルアプリ呼び出しH 5メソッド
// window['userInfo'] = window.userInfo
//   APP  JS  ,          window   ,   Vue methods   
// vue    main.js      
// app   ,        
window['userInfo'] = (data) => {
  if (typeof data == 'object') {
    sessionStorage.setItem('userdata', JSON.stringify(data))
    vm.$store.state.userdata = data
  } else {
    sessionStorage.setItem('userdata', data)
    let user = JSON.parse(data)
    vm.$store.state.userdata = user
  }
}

H 5原生アプリページをジャンプ
// actuive   APP        ,    /IOS    

window.location.href = 'actuive://data';     APP  
window.location.href = 'actuive://data/gotologin'    APP     
window.location.href = `actuive://data/${this.workDetail.opus_id}/${this.videodata.direction}`    APP    ,         APP

H 5アプリのダウンロードをクリック
//     APP,  Ios/  ,          APP
// Android_Dow_Path        
// IOS_Dow_Path  IOS    
// 'actuive://data'   app     ,  APP(      APP  ,   APP     )

export const openApp = () => {
  let platform;
  if (window) platform = sessionStorage.platform || ''
  var Android_Dow_Path = `xxxx?f=${platform}`;
  var IOS_Dow_Path = `xxxx?f=${platform}`;
  if (window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
    var APPCommon = {
      init: function () {
        this.openApp();
      },
      openApp: function () {
        var this_ = this;
        if (this_.isWeixin() || this_.isWeibo()) {
          if (navigator.userAgent.match(/android/i)) {
            window.location = Android_Dow_Path;
          } else {
            window.location = IOS_Dow_Path;
          }
        } else {
          if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
            var loadDateTime = new Date();
            window.setTimeout(function () {
              var timeOutDateTime = new Date();
              if (timeOutDateTime - loadDateTime < 5000) {
                window.location = IOS_Dow_Path;
              } else {
                window.close();
              }
            }, 2000);
            window.location = 'actuive://data';
          } else if (navigator.userAgent.match(/android/i)) {
            try {
              window.location = 'actuive://data';
              setTimeout(function () {
                window.location = Android_Dow_Path;
              }, 500);
            } catch (e) { }
          }
        }
      },
      // UA  
      isWeixin: function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
          return true;
        } else {
          return false;
        }
      },
      isWeibo: function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/WeiBo/i) == "weibo") {
          return true;
        } else {
          return false;
        }
      },
      isAndroid: function () {
        return navigator.userAgent.match(/Android/i) ? true : false;
      },
      isMobileQQ: function () {
        var ua = navigator.userAgent;
        return /(iPad|iPhone|iPod).*? (IPad)?QQ\/([\d\.]+)/.test(ua) || /\bV1_AND_SQI?_([\d\.]+)(.*? QQ\/([\d\.]+))?/.test(ua);
      },
      isIOS: function () {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
      },
    }
    APPCommon.init()
  } else {
    // console.log('PC ')
    alert('         !')
  }
}