从h5 唤起 APP 【uni-app】

参考文档:

1.uni 安卓设置 UrlSchemes: https://ask.dcloud.net.cn/article/409

2.uni ios 设置 UrlSchemes: https://ask.dcloud.net.cn/article/64

安卓

在manifest.json文件的"plus"->"distribute"->"google"下添加schemes节点数据如下:

"plus": {  
"distribute": {  
    "google": {  
        "schemes": [  
            "test"  // 设置
        ],  
        //...  
    },  

苹果

在manifest.json的"app-plus"->"distribute"->"ios"节点下添加urltypes数据:

"plus": {  
    "distribute": {  
        "apple": {  
            "urltypes": [  
                    {  
                        "urlidentifier":"com.xxx.test",  
                        "urlschemes": [  
                            "test"  
                        ]  
                    }  
            ],  
            //...  
        },  
        //...  
    },  
    //...  
}, 

h5  打开app  ,百度浏览器不支持

openAPP(){
        if(this.model === 'iPhone'){
          if(this.searchCode){
            window.location.href = "test://"+this.searchCode + '//' +this.inviteCode
          }else{
            window.location.href = "test://"
          }
          setTimeout(function(){
           // 苹果下载地址
            window.location.href = 'itms-apps://itunes.apple.com/app/苹果id'
          },2000)
        }else{
          if(this.searchCode){
             window.location.href = "test://" + this.searchCode +'//'+ this.inviteCode
          }else{
            window.location.href = "test://"
          }
          setTimeout(function(){
          // app 下载地址
          },2000)
        }
      },        

APP  获取urlscheme启动传递的参数

 var args= plus.runtime.arguments;  
    if(args){  
        // 处理args参数,如直达到某新页面等  
    }  

清除urlscheme启动传递的参数(一定要这样,不然清不掉)

plus.runtime.arguments = null
plus.runtime.arguments = ''

 

posted @ 2022-02-10 16:30  。啊月  阅读(996)  评论(0编辑  收藏  举报