Skip to content

Commit 258705a

Browse files
committed
feat(root): 发布 2.0.0 版本
新增 scheme 属性,移除 protocol 属性,outchain 属性中 protocal 改为 protocol,针对 ios qq 禁止 scheme 和 universalLink,在 ios qq 中直接唤起 app store
1 parent 80016d6 commit 258705a

File tree

8 files changed

+146
-55
lines changed

8 files changed

+146
-55
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,37 @@ callLib.open({
6262

6363
下面所有不是必填的,如果你不需要传值,就不要写这个属性,而不是传递一个空字符串或者空对象,callapp-lib 并未对这种情况进行严格的检测。
6464

65-
### protocol
65+
### scheme
6666

67-
类型: `string`
67+
类型: `object`
6868
必填: ✅
6969

70-
URL Scheme 的 scheme 字段,是你要打开的 APP 的标识
70+
用来配置 URL Scheme 所必须的那些字段。
71+
72+
+ protocol
73+
74+
类型: `string`
75+
必填: ✅
76+
77+
APP 协议,URL Scheme 的 scheme 字段,就是你要打开的 APP 的标识。
78+
79+
+ host
80+
81+
类型: `string`
82+
必填: ❎
83+
84+
URL Scheme 的 host 字段。
85+
86+
+ port
87+
88+
类型: `string` | `number`
89+
必填: ❎
90+
91+
URL Scheme 的 port 字段。
92+
93+
### <s>protocol</s>
94+
95+
callapp-lib 2.0.0 版本已移除,原先的 protocol 移入到新增的 scheme 属性中
7196

7297
### outChain
7398

@@ -78,9 +103,9 @@ URL Scheme 的 scheme 字段,是你要打开的 APP 的标识
78103

79104
例:`youku://ykshortvideo?url=xxx`
80105

81-
+ protocal
106+
+ protocol (2.0.0 版本由原先的 protocal 修改为 protocol,原先的 protocal 是拼写错误)
82107

83-
同 URL Scheme 的 scheme 字段,在你的 APP 就和上面的 protocal 属性值相同,在其他 APP 打开就传该 APP 的 scheme 标识。
108+
同 URL Scheme 的 scheme 字段,在你的 APP 就和上面的 protocol 属性值相同,在其他 APP 打开就传该 APP 的 scheme 标识。
84109

85110
+ path
86111

dist/index.umd.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(function (global, factory) {
22
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
33
typeof define === 'function' && define.amd ? define(factory) :
4-
(global.CallApp = factory());
5-
}(this, (function () { 'use strict';
4+
(global = global || self, global.CallApp = factory());
5+
}(this, function () { 'use strict';
66

77
function unwrapExports (x) {
88
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -521,13 +521,21 @@
521521
function buildScheme(config, options) {
522522
var path = config.path,
523523
param = config.param;
524+
// callapp-lib 2.0.0 版本移除 protocol 属性,添加 scheme 属性,详细用法见 README.md
524525

526+
var _options$scheme = options.scheme,
527+
host = _options$scheme.host,
528+
port = _options$scheme.port,
529+
protocol = _options$scheme.protocol;
530+
531+
var portPart = port ? ':' + port : '';
532+
var hostPort = host ? '' + host + portPart + '/' : '';
525533
var query = typeof param !== 'undefined' ? _Object$keys(param).map(function (key) {
526534
return key + '=' + param[key];
527535
}).join('&') : '';
528536
var urlQuery = query ? '?' + query : '';
529537

530-
return options.protocol + '://' + path + urlQuery;
538+
return protocol + '://' + hostPort + path + urlQuery;
531539
}
532540

533541
/**
@@ -542,11 +550,11 @@
542550
var uri = buildScheme(config, options);
543551

544552
if (typeof outChain !== 'undefined' && outChain) {
545-
var protocal = outChain.protocal,
553+
var protocol = outChain.protocol,
546554
path = outChain.path,
547555
key = outChain.key;
548556

549-
uri = protocal + '://' + path + '?' + key + '=' + encodeURIComponent(uri);
557+
uri = protocol + '://' + path + '?' + key + '=' + encodeURIComponent(uri);
550558
}
551559

552560
return uri;
@@ -828,7 +836,8 @@
828836
}
829837

830838
if (browser.isIos) {
831-
if (browser.isWechat) {
839+
// 近期ios版本qq禁止了scheme和universalLink唤起app,安卓不受影响 - 18年12月23日
840+
if (browser.isWechat || browser.isQQ) {
832841
evokeByLocation(appstore);
833842
} else if (getIOSVersion() < 9) {
834843
evokeByIFrame(schemeURL);
@@ -865,4 +874,4 @@
865874

866875
return CallApp;
867876

868-
})));
877+
}));

dist/index.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class CallApp {
100100
}
101101

102102
if (browser.isIos) {
103-
if (browser.isWechat) {
103+
// 近期ios版本qq禁止了scheme和universalLink唤起app,安卓不受影响 - 18年12月23日
104+
if (browser.isWechat || browser.isQQ) {
104105
evokeByLocation(appstore);
105106
} else if ((getIOSVersion() < 9)) {
106107
evokeByIFrame(schemeURL);

package-lock.json

Lines changed: 62 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "callapp-lib",
3-
"version": "1.7.3",
3+
"version": "2.0.0",
44
"description": "call native webview from webpage",
55
"main": "dist/index.umd.js",
66
"scripts": {
@@ -49,12 +49,12 @@
4949
"eslint-config-airbnb-base": "^12.1.0",
5050
"eslint-plugin-import": "^2.13.0",
5151
"husky": "^1.1.1",
52-
"rollup": "^0.63.4",
52+
"rollup": "^0.68.1",
5353
"rollup-plugin-babel": "^3.0.7",
5454
"rollup-plugin-commonjs": "^9.1.3",
5555
"rollup-plugin-eslint": "^5.0.0",
5656
"rollup-plugin-node-resolve": "^3.3.0",
57-
"rollup-plugin-uglify": "^4.0.0"
57+
"rollup-plugin-uglify": "^6.0.0"
5858
},
5959
"browserslist": [
6060
"Android > 4",

rollup.config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import babel from 'rollup-plugin-babel';
44
import { eslint } from 'rollup-plugin-eslint';
55
import { uglify } from 'rollup-plugin-uglify';
66

7-
export default {
7+
export default [{
88
input: 'index.js',
99
output: {
1010
format: 'umd',
@@ -27,4 +27,26 @@ export default {
2727
}),
2828
uglify(),
2929
],
30-
};
30+
}, {
31+
input: 'index.js',
32+
output: {
33+
format: 'umd',
34+
name: 'CallApp',
35+
file: 'dist/index.umd.js',
36+
},
37+
plugins: [
38+
resolve({
39+
jsnext: true,
40+
main: true,
41+
browser: true,
42+
}),
43+
commonjs(),
44+
eslint({
45+
exclude: 'node_modules/**',
46+
}),
47+
babel({
48+
exclude: 'node_modules/**',
49+
runtimeHelpers: true,
50+
}),
51+
],
52+
}];

sources/generate.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77
export function buildScheme(config, options) {
88
const { path, param } = config;
9-
const query = typeof param !== 'undefined'
10-
? Object.keys(param).map(key => `${key}=${param[key]}`).join('&')
11-
: '';
9+
// callapp-lib 2.0.0 版本移除 protocol 属性,添加 scheme 属性,详细用法见 README.md
10+
const { host, port, protocol } = options.scheme;
11+
const portPart = port ? `:${port}` : '';
12+
const hostPort = host ? `${host}${portPart}/` : '';
13+
const query = typeof param !== 'undefined' ? Object.keys(param).map(key => `${key}=${param[key]}`).join('&') : '';
1214
const urlQuery = query ? `?${query}` : '';
1315

14-
return `${options.protocol}://${path}${urlQuery}`;
16+
return `${protocol}://${hostPort}${path}${urlQuery}`;
1517
}
1618

1719
/**
@@ -25,8 +27,8 @@ export function generateScheme(config, options) {
2527
let uri = buildScheme(config, options);
2628

2729
if (typeof outChain !== 'undefined' && outChain) {
28-
const { protocal, path, key } = outChain;
29-
uri = `${protocal}://${path}?${key}=${encodeURIComponent(uri)}`;
30+
const { protocol, path, key } = outChain;
31+
uri = `${protocol}://${path}?${key}=${encodeURIComponent(uri)}`;
3032
}
3133

3234
return uri;

0 commit comments

Comments
 (0)