UniversalLinks

http://strivingboy.github.io/blog/2015/09/27/ios9/
https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW1

跳转淘宝商品搜索页

  1. try {
  2. // #ifdef APP-PLUS
  3. if (plus.runtime.isApplicationExist({ pname: 'com.taobao.taobao', action: 'taobao://' })) {
  4. if (plus.os.name == 'Android') {
  5. plus.runtime.openURL('taobao://s.taobao.com/search?q=1', error => {
  6. console.log('Open system default browser failed: ' + error);
  7. }, 'com.taobao.taobao');
  8. } else if (plus.os.name == 'iOS') {
  9. const action = {
  10. action: `taobao://s.taobao.com/search?q=` + encodeURI(this.title)
  11. };
  12. plus.runtime.launchApplication(action, function(e) {
  13. console.log('Open system default browser failed: ' + e.message);
  14. });
  15. }
  16. } else {
  17. uni.showToast({
  18. title: '未检测到淘宝',
  19. icon: 'none'
  20. });
  21. //TODO
  22. }
  23. // #endif
  24. // #ifdef H5
  25. location.href = 'taobao://s.taobao.com/search?q=' + this.title;
  26. // #endif
  27. } catch (e) {
  28. // TODO
  29. }

淘宝首页跳转

  1. //android
  2. plus.runtime.launchApplication({
  3. pname: 'com.taobao.taobao'
  4. },function(e) {
  5. console.log('Open system default browser failed: ' + e.message);
  6. });
  7. plus.runtime.openURL(`taobao://s.taobao.com`, error => {
  8. console.log('Open system default browser failed: ' + error);
  9. }, 'com.taobao.taobao');
  10. //ios
  11. plus.runtime.openURL('taobao://s.taobao.com');
  12. const action = {
  13. action: `taobao://s.taobao.com`
  14. };
  15. plus.runtime.launchApplication(action, function(e) {
  16. console.log('Open system default browser failed: ' + e.message);
  17. });

常用Scheme

  1. [
  2. // 只在 ios 中生效
  3. {
  4. name: 'App Store',
  5. scheme: 'itms-apps://'
  6. },
  7. {
  8. name: '支付宝',
  9. pname: 'com.eg.android.AlipayGphone',
  10. scheme: 'alipay://'
  11. },
  12. {
  13. name: '淘宝',
  14. pname: 'com.taobao.taobao',
  15. scheme: 'taobao://'
  16. },
  17. {
  18. name: 'QQ',
  19. pname: 'com.tencent.mobileqq',
  20. scheme: 'mqq://'
  21. },
  22. {
  23. name: '微信',
  24. pname: 'com.tencent.mm',
  25. scheme: 'weixin://'
  26. },
  27. {
  28. name: '京东',
  29. pname: 'com.jingdong.app.mall',
  30. scheme: 'openApp.jdMobile://'
  31. },
  32. {
  33. name: '新浪微博',
  34. pname: 'com.sina.weibo',
  35. scheme: 'sinaweibo://'
  36. },
  37. {
  38. name: '优酷',
  39. pname: 'com.youku.phone',
  40. scheme: 'youku://'
  41. }
  42. ]

微信跳转

  1. // #ifdef APP-PLUS
  2. if(plus.runtime.isApplicationExist({ pname: 'com.taobao.taobao', action: 'taobao://' })) {
  3. if(this.platform == 'ios') {
  4. plus.runtime.openURL('weixin://');
  5. } else {
  6. plus.runtime.openURL(`weixin://`, error => {
  7. console.log('Open system default browser failed: ' + error);
  8. }, 'com.tencent.mm');
  9. }
  10. } else {
  11. uni.showToast({
  12. title: '未检测到微信',
  13. icon: 'none'
  14. });
  15. }
  16. // #endif
  17. // #ifdef H5
  18. location.href = 'weixin://';
  19. // #endif
  1. //安卓跳转解决方案
  2. var Intent = plus.android.importClass("android.content.Intent");
  3. var ComponentName = plus.android.importClass('android.content.ComponentName')
  4. var intent = new Intent();
  5. intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"));
  6. // intent.putExtra("LauncherUI.From.Scaner.Shortcut", true);
  7. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  8. intent.setAction("android.intent.action.VIEW");
  9. var main = plus.android.runtimeMainActivity();
  10. main.startActivity(intent);

参考文档

https://ask.dcloud.net.cn/article/35621
http://www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.openURL