uniapp解决H5唤醒APP

H5唤醒APP

解决H5唤醒指定APP

设置schemes

- Android

打开项目manifest.json文件源码视图
在manifest.json文件的"app-plus">>“distribute”>>"android"下添加schemes节点数据
自定义字符串,不要使用特殊符号和中文,可设置多个,比如设置nekomata,那么唤起的app的scheme协议就是 nekomata://

"app-plus": {
     
  "distribute": {
     
    "android": {
     
      "schemes" : [ "nekomata" ]
    }
  }
}

- iOS

打开项目manifest.json文件源码视图
在manifest.json文件的"app-plus">>“distribute”>>"ios"下添加schemes节点数据

"app-plus": {
     
  "distribute": {
     
    "ios": {
     
      "urltypes": [{
     
          "urlidentifier":"com.nekomata.app",  
          "urlschemes": [  
            "nekomata"  
          ]  
      }],
    }
  }
}

设置应用跳转白名单

打开项目manifest.json文件源码视图
在manifest.json文件的"app-plus">>“distribute”>>"ios"下添加schemes节点数据

"app-plus": {
     
  "distribute": {
     
    "ios": {
     
      "urlschemewhitelist" : [ "nekomata" ],
    }
  }
}

调用方式

<a href="nekomata://index?a=1">唤起app<a>
location.href = 'nekomata://index?' + 'a=1'

app参数处理

let args = plus.runtime.arguments;
  console.log(plus.runtime.arguments, typeof args, 'plus.runtime.arguments');
  if (typeof args == 'string' || typeof args == 'object') {
     
    args = args.split('home?');
    console.log(args,'args');
    if (args.length == 2 && args[1]) {
     
      args = args[1];
      try {
     
        //获取到参数,处理跳转逻辑
      } catch (e) {
     
        console.log('处理参数失败', e);
      }
   }
   
   //值清空这里有坑的,可能是官方bug
   plus.runtime.arguments = null;
   plus.runtime.arguments = '';
   return false;
}

你可能感兴趣的:(uniapp,uni-app)