├── .gitignore ├── LICENSE ├── README.md ├── build ├── index.js ├── out ├── XGPush.html ├── external-EventEmitter.html ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.svg │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.svg │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.svg │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.svg │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-LightItalic-webfont.svg │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.svg │ └── OpenSans-Regular-webfont.woff ├── index.html ├── index.js.html ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js ├── styles │ ├── jsdoc-default.css │ ├── prettify-jsdoc.css │ └── prettify-tomorrow.css └── tutorial-README.html ├── package.json ├── plugin.xml ├── sdk ├── VERSION.md ├── android │ ├── Other-Platform-SO │ │ ├── arm64-v8a │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ ├── armeabi-v7a │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ ├── armeabi │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ ├── mips │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ ├── mips64 │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ ├── x86 │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ │ └── x86_64 │ │ │ ├── libtpnsSecurity.so │ │ │ └── libxguardian.so │ └── libs │ │ ├── Xg_sdk_v2.47_20161026_0936.jar │ │ ├── android-support-v4.jar │ │ ├── armeabi │ │ ├── libtpnsSecurity.so │ │ └── libxguardian.so │ │ ├── jg_filter_sdk_1.1.jar │ │ └── wup-1.0.0.E-SNAPSHOT.jar └── ios │ └── demo │ └── sdk │ ├── XGPush.h │ ├── XGSetting.h │ └── libXG-SDK.a ├── src ├── android │ ├── DiskHeap.java │ ├── PushPlugin.java │ ├── XGPush.java │ ├── XGReceiver.java │ └── v2 │ │ ├── ReceiverManager.java │ │ ├── XGCordova.java │ │ ├── XGCordovaOperateCallback.java │ │ ├── XGCordovaPushReceiver.java │ │ └── XGPushPlugin.java └── ios │ ├── AppDelegate+CDVXGPush.h │ ├── AppDelegate+CDVXGPush.m │ ├── CDVRegisterNotification.h │ ├── CDVRegisterNotification.m │ ├── CDVXGPushPlugin.h │ ├── CDVXGPushPlugin.m │ ├── CDVXGPushUtil.h │ └── CDVXGPushUtil.m ├── tutorial └── README.md └── www └── xgpush.js /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 gengen1988 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XGPush 腾讯信鸽推送 for Cordova 2 | 3 | - [170109] 升级 SDK 4 | - [160119] 升级 SDK 5 | - [151229] iOS SDK 版本更新至 2.4.5,重新规划 SDK 存储路径 6 | - [151015] 庆祝 20 Stars,SDK 升级 7 | 8 | SDK | version 9 | ------- | -------------------------------- 10 | android | Xg-Push-SDK-Android-2.47 11 | ios | Xg-Push-SDK-iOS-2.5.0 12 | 13 | 腾讯信鸽推送服务:http://xg.qq.com/ 14 | 15 | Cordova 版本:3.x / 4.x / 5.x 16 | 17 | 这个插件支持通知与消息,同时针对混合应用的生命周期进行了处理,保证消息的抵达。 18 | 19 | ## 安装方法 20 | 21 | 打开控制台,进入 Cordova 项目目录,输入: 22 | 23 | ```bash 24 | cordova plugin add https://github.com/ETENG-OSP/xgpush-cordova --save \ 25 | --variable ACCESS_ID="Your Access ID" \ 26 | --variable ACCESS_KEY="Your Access Key" 27 | ``` 28 | 29 | ## 使用方法 30 | 31 | 安装完成即可接收推送通知。这种用法适合于仅需要偶尔向全部用户发信息的情况。 32 | 33 | 如果需要精确控制,参考以下 API 和事件。 34 | 35 | ### API 36 | 37 | * __xgpush.registerPush([alias])__: 注册设备 38 | 39 | 这个方法可以手动注册设备。如果需要为接收推送的设备取别名以便有针对性的通知,需要在 `deviceready` 后注册别名: 40 | 41 | ```js 42 | // 这里的别名是可选的,不传代表没用别名 43 | xgpush.registerPush('tom'); 44 | ``` 45 | 46 | 如果需要结果,可以用 Promise 的形式获取: 47 | 48 | ```js 49 | xgpush.registerPush('tom').then(function(results) { 50 | // results 里有 flag 和 data 51 | alert('设备的 token 是: ' + results.data); 52 | }); 53 | ``` 54 | 55 | 可以重复注册,下一个别名会替换上一个别名。 56 | 57 | * __xgpush.unregisterPush()__: 注销设备 58 | 59 | 如果不想接收推送,使用 `xgpush.unregisterPush`: 60 | 61 | ```js 62 | xgpush.unregisterPush() 63 | ``` 64 | 65 | 这个方法也返回 Promise。 66 | 67 | ### 事件 68 | 69 | * __textmessage__: 文本消息 70 | 71 | 如果需要接受消息,直接在代码里处理,可以监听 `textmessage` 事件: 72 | 73 | ```js 74 | xgpush.on('textmessage', function(e) { 75 | // 事件处理方法 76 | alert(JSON.stringify(arguments, null, 2)); 77 | }); 78 | ``` 79 | 80 | 事件采用了与 Node.js 事件兼容的 eventemitter3。具体方法参考:https://nodejs.org/api/events.html 81 | 82 | ## 用例 83 | 84 | 如果需要推送一条信息,用户在点击该信息后进入应用,同时触发程序逻辑。可以发送一个带有自定义 URL scheme 的通知。 85 | 86 | 参考这个插件:https://github.com/EddyVerbruggen/Custom-URL-scheme 87 | 88 | 89 | ## 注意事项 90 | 91 | ### armv7s 与 xcode 6 92 | 93 | 如果执行 `cordova build --device --release` 不成功,请去掉 `build.js` 里的 armv7s。 94 | 95 | 参考: 96 | https://issues.apache.org/jira/browse/CB-8788 97 | 98 | ### 不同平台 so 文件 99 | 100 | 这个插件内置了 armeabi 的库文件。如果目标平台不是 armeabi,请到 http://xg.qq.com/xg/help/ctr_help/download 下载对应版本的 SDK。 101 | 102 | 以下引用 SDK 中的说明: 103 | 104 | > 1. 信鸽的 .so 支持所有的 android 平台,但考虑到平时接入一般只需要 armeabi 平台,因此 libs 目录只提供该平台的 .so,其它平台可在上层目录的 All-Platform-SO 找到。 105 | > 106 | > 2. 嵌入 .so 可能存在的问题: 107 | > 1. so 文件与 jar 包不匹配。 108 | > 109 | > 解决办法:在更新 jar 时同时更新对应的 so 文件; 110 | > 111 | > 2. 当前工程已有某些平台的 so,如只有 armeabi 平台,却添加信鸽所有平台导致打包时异常。 112 | > 113 | > 解决办法:只添加当前工程已有的平台的信鸽 so 文件。具体可参考网上或以下示例: 114 | > 115 | > ``` 116 | > armeabi !此平台既有当前存在so又有信鸽,正常! 117 | > --libCurrent.so 当前工程已有so 118 | > --libtpnsSecurity.so 信鸽 119 | > --libtpnsWatchdog.so 信鸽 120 | > 121 | > armeabi-v7a !此平台既有当前存在so又有信鸽,正常! 122 | > --libCurrent.so 当前工程已有so 123 | > --libtpnsSecurity.so 信鸽 124 | > --libtpnsWatchdog.so 信鸽 125 | > 126 | > mips !!!错误,由于此平台只有信鸽,必须删掉mips目录!!! 127 | > --libtpnsSecurity.so 信鸽 128 | > --libtpnsWatchdog.so 信鸽 129 | > 130 | > x86 !!!错误,由于此平台只有信鸽,必须删掉x86目录!!! 131 | > --libtpnsSecurity.so 信鸽 132 | > --libtpnsWatchdog.so 信鸽 133 | > ``` 134 | > 135 | > 3. 若当前工程不存在 so 文件。 136 | > 137 | > 解决办法:可复制所有信鸽平台或只复制 armeabi 平台。 138 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf .tmp 4 | mkdir .tmp 5 | browserify index.js > .tmp/bundle.js 6 | uglifyjs .tmp/bundle.js -c -m > .tmp/bundle.min.js 7 | 8 | cat > www/xgpush.js << EOL 9 | `cat .tmp/bundle.min.js` 10 | var XGPush = window._XGPush; 11 | delete window._XGPush; 12 | module.exports = new XGPush(require('cordova/exec')); 13 | EOL 14 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | if (!window.Promise) { 2 | require('es6-promise').polyfill(); 3 | } 4 | 5 | /** 6 | * Node.js 的事件类 7 | * 8 | * @external EventEmitter 9 | * @see {@link https://nodejs.org/api/events.html} 10 | */ 11 | var EventEmitter = require('eventemitter3'); 12 | 13 | /** 14 | * 信鸽 Cordova 服务类,用于注册。 15 | * 16 | * @class 17 | * @extends external:EventEmitter 18 | * @param {function} exec - cordova 插件接口 19 | * @tutorial README.md 20 | */ 21 | function XGPush(exec) { 22 | EventEmitter.call(this); 23 | this.exec = exec; 24 | this.registerPush(); 25 | this.registerReceiver( 26 | this.eventSuccess.bind(this), 27 | this.eventError.bind(this) 28 | ); 29 | } 30 | 31 | XGPush.prototype = new EventEmitter(); 32 | 33 | XGPush.SERVICE = 'XGPush'; 34 | XGPush.ACTION_REGISTER_PUSH = 'registerpush'; 35 | XGPush.ACTION_UNREGISTER_PUSH = 'unregisterpush'; 36 | XGPush.ACTION_ADD_LISTENER = 'addlistener'; 37 | 38 | XGPush.prototype.eventSuccess = function(results) { 39 | console.log('receive message:', results); 40 | this.emit('textmessage', results); 41 | }; 42 | 43 | XGPush.prototype.eventError = function(err) { 44 | console.log('receive error:', err); 45 | this.emit('error', err); 46 | }; 47 | 48 | XGPush.prototype.registerReceiver = function(success, error) { 49 | var exec = this.exec; 50 | exec( 51 | success, error, 52 | XGPush.SERVICE, XGPush.ACTION_ADD_LISTENER, 53 | [] 54 | ); 55 | }; 56 | 57 | /** 58 | * 与信鸽服务注册。注册的时候可以填别名,按照别名发送时,只有经过注册的别名才会收到推送。 59 | * 60 | * 可以重复调用这个方法。如果变更别名,则替换原有注册的结果。 61 | * 62 | * @param {string} [alias] - 设备的别名 63 | * @return {external:Promise} 判断是否成功的 Promise 64 | * @example 65 | * // 直接注册 66 | * xgpush.registerPush().then(function() { 67 | * console.log('success'); 68 | * 69 | * }).catch(function(errCode) { 70 | * console.log('oh no: ' + errCode); 71 | * }); 72 | * 73 | * // 带设备别名注册 74 | * xgpush.registerPush('foo').then(function() { 75 | * console.log('success'); 76 | * 77 | * }).catch(function(errCode) { 78 | * console.log('oh no: ' + errCode); 79 | * }); 80 | */ 81 | XGPush.prototype.registerPush = function(alias) { 82 | var exec = this.exec; 83 | return new Promise(function(resolve, reject) { 84 | exec( 85 | resolve, reject, 86 | XGPush.SERVICE, XGPush.ACTION_REGISTER_PUSH, 87 | [alias] 88 | ); 89 | }); 90 | }; 91 | 92 | /** 93 | * 取消注册 94 | * 95 | * @return {external:Promise} 完成后的回调 96 | */ 97 | XGPush.prototype.unregisterPush = function() { 98 | var exec = this.exec; 99 | return new Promise(function(resolve, reject) { 100 | exec( 101 | resolve, reject, 102 | XGPush.SERVICE, XGPush.ACTION_UNREGISTER_PUSH, 103 | []); 104 | }); 105 | }; 106 | 107 | /** 108 | * 事件的处理回调 109 | * 110 | * @callback XGPush#EventListener 111 | * @param {event} e - 事件内容 112 | */ 113 | 114 | /** 115 | * 收到信鸽消息时的事件 116 | * 117 | * @event XGPush#textmessage 118 | * @property {string} content - 消息正文内容 119 | * @property {Object} customContent - 消息自定义 key-value 120 | * @property {string} title - 消息标题 121 | */ 122 | 123 | module.exports = XGPush; 124 | window._XGPush = XGPush; 125 | -------------------------------------------------------------------------------- /out/XGPush.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: XGPush 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: XGPush

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

32 | XGPush 33 |

34 | 35 | 36 |
37 | 38 |
39 |
40 | 41 | 42 | 43 | 44 | 45 |

new XGPush(exec)

46 | 47 | 48 | 49 | 50 | 51 |
52 | 信鸽 Cordova 服务类,用于注册。 53 |
54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
Parameters:
64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
NameTypeDescription
exec 92 | 93 | 94 | function 95 | 96 | 97 | 98 | cordova 插件接口
110 | 111 | 112 | 113 | 114 | 115 | 116 |
117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |
Source:
144 |
147 | 148 | 149 | 150 |
Tutorials:
151 |
152 |
    153 |
  • Tutorial: README.md
  • 154 |
155 |
156 | 157 | 158 | 159 | 160 | 161 |
162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 |
180 | 181 | 182 |

Extends

183 | 184 | 185 | 186 | 187 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 |

Methods

206 | 207 | 208 | 209 | 210 | 211 | 212 |

registerPush(aliasopt) → {external:Promise}

213 | 214 | 215 | 216 | 217 | 218 |
219 | 与信鸽服务注册。注册的时候可以填别名,按照别名发送时,只有经过注册的别名才会收到推送。 220 | 221 | 可以重复调用这个方法。如果变更别名,则替换原有注册的结果。 222 |
223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
Parameters:
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 270 | 271 | 272 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 |
NameTypeAttributesDescription
alias 263 | 264 | 265 | string 266 | 267 | 268 | 269 | 273 | 274 | <optional>
275 | 276 | 277 | 278 | 279 | 280 |
设备的别名
291 | 292 | 293 | 294 | 295 | 296 | 297 |
298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 |
Source:
325 |
328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 |
336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 |
Returns:
350 | 351 | 352 |
353 | 判断是否成功的 Promise 354 |
355 | 356 | 357 | 358 |
359 |
360 | Type 361 |
362 |
363 | 364 | external:Promise 365 | 366 | 367 |
368 |
369 | 370 | 371 | 372 | 373 |
Example
374 | 375 |
// 直接注册
376 | xgpush.registerPush().then(function() {
377 |   console.log('success');
378 | 
379 | }).catch(function(errCode) {
380 |   console.log('oh no: ' + errCode);
381 | });
382 | 
383 | // 带设备别名注册
384 | xgpush.registerPush('foo').then(function() {
385 |   console.log('success');
386 | 
387 | }).catch(function(errCode) {
388 |   console.log('oh no: ' + errCode);
389 | });
390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 |

unregisterPush() → {external:Promise}

399 | 400 | 401 | 402 | 403 | 404 |
405 | 取消注册 406 |
407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 |
421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 |
Source:
448 |
451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 |
459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 |
Returns:
473 | 474 | 475 |
476 | 完成后的回调 477 |
478 | 479 | 480 | 481 |
482 |
483 | Type 484 |
485 |
486 | 487 | external:Promise 488 | 489 | 490 |
491 |
492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 |

Type Definitions

502 | 503 | 504 | 505 | 506 | 507 | 508 |

EventListener(e)

509 | 510 | 511 | 512 | 513 | 514 |
515 | 事件的处理回调 516 |
517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 |
Parameters:
527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 |
NameTypeDescription
e 555 | 556 | 557 | event 558 | 559 | 560 | 561 | 事件内容
573 | 574 | 575 | 576 | 577 | 578 | 579 |
580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 |
Source:
607 |
610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 |
618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 |

Events

639 | 640 | 641 | 642 | 643 | 644 | 645 |

textmessage

646 | 647 | 648 | 649 | 650 | 651 |
652 | 收到信鸽消息时的事件 653 |
654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 |
Properties:
668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 |
NameTypeDescription
content 697 | 698 | 699 | string 700 | 701 | 702 | 703 | 消息正文内容
customContent 720 | 721 | 722 | Object 723 | 724 | 725 | 726 | 消息自定义 key-value
title 743 | 744 | 745 | string 746 | 747 | 748 | 749 | 消息标题
761 | 762 | 763 | 764 | 765 |
766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 |
Source:
793 |
796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 |
804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 |
823 | 824 |
825 | 826 | 827 | 828 | 829 |
830 | 831 | 834 | 835 |
836 | 837 | 840 | 841 | 842 | 843 | 844 | -------------------------------------------------------------------------------- /out/external-EventEmitter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: External: EventEmitter 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

External: EventEmitter

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

32 | EventEmitter 33 |

34 | 35 | 36 |
37 | 38 |
39 |
40 | 41 | 42 |
Node.js 的事件类
43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
Source:
76 |
79 | 80 | 81 | 82 | 83 | 84 |
See:
85 |
86 | 89 |
90 | 91 | 92 | 93 |
94 | 95 | 96 | 97 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 |
118 | 119 |
120 | 121 | 122 | 123 | 124 |
125 | 126 | 129 | 130 |
131 | 132 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /out/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/out/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /out/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 55 | 56 |
57 | 58 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /out/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: index.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: index.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
/**
 30 |  * Node.js 的事件类
 31 |  *
 32 |  * @external EventEmitter
 33 |  * @see {@link https://nodejs.org/api/events.html}
 34 |  */
 35 | var EventEmitter = require('eventemitter3');
 36 | 
 37 | /**
 38 |  * 信鸽 Cordova 服务类,用于注册。
 39 |  *
 40 |  * @class
 41 |  * @extends external:EventEmitter
 42 |  * @param {function} exec - cordova 插件接口
 43 |  * @tutorial README.md
 44 |  */
 45 | function XGPush(exec) {
 46 |   EventEmitter.call(this);
 47 |   this.exec = exec;
 48 |   this.registerPush();
 49 |   this.registerReceiver(
 50 |     this.eventSuccess.bind(this),
 51 |     this.eventError.bind(this)
 52 |   );
 53 | }
 54 | 
 55 | XGPush.prototype = new EventEmitter();
 56 | 
 57 | XGPush.SERVICE = 'XGPush';
 58 | XGPush.ACTION_REGISTER_PUSH = 'registerpush';
 59 | XGPush.ACTION_UNREGISTER_PUSH = 'unregisterpush';
 60 | XGPush.ACTION_ADD_LISTENER = 'addlistener';
 61 | 
 62 | XGPush.prototype.eventSuccess = function(results) {
 63 |   console.log('receive message:', results);
 64 |   this.emit('textmessage', results);
 65 | };
 66 | 
 67 | XGPush.prototype.eventError = function(err) {
 68 |   console.log('receive error:', err);
 69 |   this.emit('error', err);
 70 | };
 71 | 
 72 | XGPush.prototype.registerReceiver = function(success, error) {
 73 |   var exec = this.exec;
 74 |   exec(
 75 |     success, error,
 76 |     XGPush.SERVICE, XGPush.ACTION_ADD_LISTENER,
 77 |     []
 78 |   );
 79 | };
 80 | 
 81 | /**
 82 |  * 与信鸽服务注册。注册的时候可以填别名,按照别名发送时,只有经过注册的别名才会收到推送。
 83 |  *
 84 |  * 可以重复调用这个方法。如果变更别名,则替换原有注册的结果。
 85 |  *
 86 |  * @param  {string} [alias] - 设备的别名
 87 |  * @return {external:Promise} 判断是否成功的 Promise
 88 |  * @example
 89 |  * // 直接注册
 90 |  * xgpush.registerPush().then(function() {
 91 |  *   console.log('success');
 92 |  *
 93 |  * }).catch(function(errCode) {
 94 |  *   console.log('oh no: ' + errCode);
 95 |  * });
 96 |  *
 97 |  * // 带设备别名注册
 98 |  * xgpush.registerPush('foo').then(function() {
 99 |  *   console.log('success');
100 |  *
101 |  * }).catch(function(errCode) {
102 |  *   console.log('oh no: ' + errCode);
103 |  * });
104 |  */
105 | XGPush.prototype.registerPush = function(alias) {
106 |   var exec = this.exec;
107 |   return new Promise(function(resolve, reject) {
108 |     exec(
109 |       resolve, reject,
110 |       XGPush.SERVICE, XGPush.ACTION_REGISTER_PUSH,
111 |       [alias]
112 |     );
113 |   });
114 | };
115 | 
116 | /**
117 |  * 取消注册
118 |  *
119 |  * @return {external:Promise} 完成后的回调
120 |  */
121 | XGPush.prototype.unregisterPush = function() {
122 |   var exec = this.exec;
123 |   return new Promise(function(resolve, reject) {
124 |     exec(
125 |       resolve, reject,
126 |       XGPush.SERVICE, XGPush.ACTION_UNREGISTER_PUSH,
127 |     []);
128 |   });
129 | };
130 | 
131 | /**
132 |  * 事件的处理回调
133 |  *
134 |  * @callback XGPush#EventListener
135 |  * @param {event} e - 事件内容
136 |  */
137 | 
138 | /**
139 |  * 收到信鸽消息时的事件
140 |  *
141 |  * @event XGPush#textmessage
142 |  * @property {string} content - 消息正文内容
143 |  * @property {Object} customContent - 消息自定义 key-value
144 |  * @property {string} title - 消息标题
145 |  */
146 | 
147 | module.exports = XGPush;
148 | window._XGPush = XGPush;
149 | 
150 |
151 |
152 | 153 | 154 | 155 | 156 |
157 | 158 | 161 | 162 |
163 | 164 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /out/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /out/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /out/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /out/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p p:first-child, 338 | .props td.description > p:first-child 339 | { 340 | margin-top: 0; 341 | padding-top: 0; 342 | } 343 | 344 | .params td.description > p:last-child, 345 | .props td.description > p:last-child 346 | { 347 | margin-bottom: 0; 348 | padding-bottom: 0; 349 | } 350 | 351 | .disabled { 352 | color: #454545; 353 | } 354 | -------------------------------------------------------------------------------- /out/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /out/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /out/tutorial-README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Tutorial: README 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Tutorial: README

21 | 22 |
23 | 24 |
25 | 26 | 27 |

README

28 |
29 | 30 |
31 |

XGPush 腾讯信鸽推送 for Cordova

腾讯信鸽推送服务:http://xg.qq.com/

32 |

信鸽 SDK 版本:2.40

33 |

Cordova 版本:3.x / 4.x / 5.x

34 |

这个插件支持通知与消息,同时针对混合应用的生命周期进行了处理,保证消息的抵达。

35 |

安装方法

打开控制台,进入 Cordova 项目目录,输入:

36 |
cordova plugin add https://github.com/gengen1988/xgpush-cordova --save \
 37 |   --variable ACCESS_ID="Your Access ID" \
 38 |   --variable ACCESS_KEY="Your Access Key"

使用方法

安装完成即可接收推送通知。

39 |

xgpush.registerPush([alias])

如果需要为接收推送的设备取别名以便有针对性的通知,需要在 deviceready 后注册别名:

40 |
// 这里的别名是可选的,不传代表没用别名
 41 | xgpush.registerPush('tom');

如果需要结果,可以用 Promise 的形式获取:

42 |
xgpush.registerPush('tom').then(function(results) {
 43 |   // results 里有 flag 和 data
 44 |   alert('设备的 token 是: ' + results.data);
 45 | });

可以重复注册,下一个别名会替换上一个别名。

46 |

xgpush.unregisterPush()

如果不想接收推送,使用 xgpush.unregisterPush

47 |
xgpush.unregisterPush().then(function() {
 48 |   // 注销结果
 49 | })

事件:textmessage

如果需要接受消息,直接在代码里处理,可以监听 textmessage 事件:

50 |
xgpush.on('textmessage', function(e) {
 51 |   // 事件处理方法
 52 |   alert(JSON.stringify(arguments, null, 2));
 53 | });

事件采用了与 Node.js 事件兼容的 eventemitter3。具体方法参考 Node.js 文档。

54 |

用例

如果需要推送一条信息,用户在点击该信息后进入应用,同时触发程序逻辑。可以发送一个带有自定义 URL scheme 的通知。

55 |

参考这个插件:https://github.com/EddyVerbruggen/Custom-URL-scheme

56 |

注意事项

不同平台 so 文件

这个插件内置了 armeabi 的库文件。如果目标平台不是 armeabi,请到 http://xg.qq.com/xg/help/ctr_help/download 下载对应版本的 SDK。

57 |

以下引用 SDK 中的说明:

58 |
59 |
    60 |
  1. 信鸽的 .so 支持所有的 android 平台,但考虑到平时接入一般只需要 armeabi 平台,因此 libs 目录只提供该平台的 .so,其它平台可在上层目录的 All-Platform-SO 找到。

    61 |
  2. 62 |
  3. 嵌入 .so 可能存在的问题:

    63 |
      64 |
    1. so 文件与 jar 包不匹配。

      65 |

      解决办法:在更新 jar 时同时更新对应的 so 文件;

      66 |
    2. 67 |
    3. 当前工程已有某些平台的 so,如只有 armeabi 平台,却添加信鸽所有平台导致打包时异常。

      68 |

      解决办法:只添加当前工程已有的平台的信鸽 so 文件。具体可参考网上或以下示例:

      69 |
      armeabi       !此平台既有当前存在so又有信鸽,正常!
       70 | --libCurrent.so            当前工程已有so
       71 | --libtpnsSecurity.so    信鸽
       72 | --libtpnsWatchdog.so    信鸽
       73 | 
       74 | armeabi-v7a    !此平台既有当前存在so又有信鸽,正常!
       75 | --libCurrent.so            当前工程已有so
       76 | --libtpnsSecurity.so    信鸽
       77 | --libtpnsWatchdog.so    信鸽
       78 | 
       79 | mips    !!!错误,由于此平台只有信鸽,必须删掉mips目录!!!
       80 | --libtpnsSecurity.so    信鸽
       81 | --libtpnsWatchdog.so    信鸽
       82 | 
       83 | x86        !!!错误,由于此平台只有信鸽,必须删掉x86目录!!!
       84 | --libtpnsSecurity.so    信鸽
       85 | --libtpnsWatchdog.so    信鸽
    4. 86 |
    5. 若当前工程不存在 so 文件。

      87 |

      解决办法:可复制所有信鸽平台或只复制 armeabi 平台。

      88 |
    6. 89 |
    90 |
  4. 91 |
92 |
93 |
94 | 95 |
96 | 97 |
98 | 99 | 102 | 103 |
104 | 105 |
106 | Documentation generated by JSDoc 3.3.1 on Fri Jul 03 2015 19:23:23 GMT+0800 (CST) 107 |
108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xgpush-cordova", 3 | "version": "0.2.0", 4 | "description": "腾讯信鸽推送服务:http://xg.qq.com/", 5 | "main": "index.js", 6 | "dependencies": { 7 | "es6-promise": "^3.0.2", 8 | "eventemitter3": "^1.1.1" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/gengen1988/xgpush-cordova.git" 17 | }, 18 | "author": "", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/gengen1988/xgpush-cordova/issues" 22 | }, 23 | "homepage": "https://github.com/gengen1988/xgpush-cordova#readme" 24 | } 25 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | xgpush-cordova 7 | Tencent XGPush Plugin 8 | MIT 9 | Gen Liu 10 | cordova, push, chinese 11 | 12 | https://github.com/gengen1988/xgpush-cordova.git 13 | https://github.com/gengen1988/xgpush-cordova/issues 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 84 | 85 | 86 | 95 | 96 | 97 | 98 | 99 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 113 | 114 | 115 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 126 | 127 | 128 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | AccessID 165 | $ACCESS_ID 166 | AccessKey 167 | $ACCESS_KEY 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /sdk/VERSION.md: -------------------------------------------------------------------------------- 1 | --- 2 | android: Xg-Push-SDK-Android-2.47 3 | ios: Xg-Push-SDK-iOS-2.5.0 4 | --- 5 | -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/arm64-v8a/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/arm64-v8a/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/arm64-v8a/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/arm64-v8a/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/armeabi-v7a/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/armeabi-v7a/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/armeabi-v7a/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/armeabi-v7a/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/armeabi/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/armeabi/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/armeabi/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/armeabi/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/mips/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/mips/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/mips/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/mips/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/mips64/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/mips64/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/mips64/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/mips64/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/x86/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/x86/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/x86/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/x86/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/x86_64/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/x86_64/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/Other-Platform-SO/x86_64/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/Other-Platform-SO/x86_64/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/libs/Xg_sdk_v2.47_20161026_0936.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/Xg_sdk_v2.47_20161026_0936.jar -------------------------------------------------------------------------------- /sdk/android/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/android-support-v4.jar -------------------------------------------------------------------------------- /sdk/android/libs/armeabi/libtpnsSecurity.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/armeabi/libtpnsSecurity.so -------------------------------------------------------------------------------- /sdk/android/libs/armeabi/libxguardian.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/armeabi/libxguardian.so -------------------------------------------------------------------------------- /sdk/android/libs/jg_filter_sdk_1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/jg_filter_sdk_1.1.jar -------------------------------------------------------------------------------- /sdk/android/libs/wup-1.0.0.E-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/android/libs/wup-1.0.0.E-SNAPSHOT.jar -------------------------------------------------------------------------------- /sdk/ios/demo/sdk/XGPush.h: -------------------------------------------------------------------------------- 1 | // 2 | // XGPush.h 3 | // XG-SDK 4 | // 5 | // Created by xiangchen on 13-10-18. 6 | // Copyright (c) 2013年 mta. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface XGPush : NSObject 13 | 14 | /** 15 | 初始化信鸽 16 | 17 | @param appId 通过前台申请的应用ID 18 | @param appKey 通过前台申请的appKey 19 | */ 20 | +(void)startApp:(uint32_t)appId appKey:(nonnull NSString *)appKey; 21 | 22 | /** 23 | 判断当前是否是已注销状态 24 | 25 | @return 是否已经注销推送 26 | */ 27 | +(BOOL)isUnRegisterStatus; 28 | 29 | 30 | /** 31 | 查询推送是否打开(以弹窗为准) 32 | 33 | @param result 查询回调.若推送打开,回调参数为 YES, 否则为 NO 34 | */ 35 | +(void)isPushOn:(nullable void(^)(BOOL isOn)) result; 36 | 37 | /** 38 | 注册设备 39 | 40 | @param deviceToken 通过app delegate的didRegisterForRemoteNotificationsWithDeviceToken回调的获取 41 | @param successCallback 成功回调 42 | @param errorCallback 失败回调 43 | @return 获取的 deviceToken 字符串 44 | */ 45 | +(nullable NSString *)registerDevice:(nonnull NSData *)deviceToken successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 46 | 47 | /** 48 | 注册设备并且设置账号 49 | 50 | @param deviceToken 通过app delegate的didRegisterForRemoteNotificationsWithDeviceToken回调的获取 51 | @param account 需要设置的账号,长度为2个字节以上,不要使用"test","123456"这种过于简单的字符串, 52 | 若不想设置账号,请传入nil 53 | @param successCallback 成功回调 54 | @param errorCallback 失败回调 55 | @return 获取的 deviceToken 字符串 56 | */ 57 | +(nullable NSString *)registerDevice:(nonnull NSData *)deviceToken account:(nullable NSString *)account successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 58 | 59 | 60 | /** 61 | 注册设备并且设置账号, 字符串 token 版本 62 | 63 | @param deviceToken NSString *类型的 token 64 | @param account 需要设置的账号,若不想设置账号,请传入 nil 65 | @param successCallback 成功回调 66 | @param errorCallback 失败回调 67 | @return 获取的 deviceToken 字符串 68 | */ 69 | +(nullable NSString *)registerDeviceStr:(nonnull NSString *)deviceToken account:(nullable NSString *) account successCallback:(nullable void(^)(void)) successCallback errorCallback:(nullable void(^)(void))errorCallback; 70 | 71 | /** 72 | 注销设备,设备不再进行推送 73 | 74 | @param successCallback 成功回调 75 | @param errorCallback 失败回调 76 | */ 77 | +(void)unRegisterDevice:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 78 | 79 | /** 80 | 设置设备的帐号. 设置账号前需要调用一次registerDevice 81 | 82 | @param account 需要设置的账号,长度为2个字节以上,不要使用"test","123456"这种过于简单的字符串, 83 | 若不想设置账号,请传入nil 84 | @param successCallback 成功回调 85 | @param errorCallback 失败回调 86 | */ 87 | +(void)setAccount:(nonnull NSString *)account successCallback:(nullable void(^)(void)) successCallback errorCallback:(nullable void(^)(void)) errorCallback; 88 | 89 | 90 | /** 91 | 删除已经设置的账号 92 | 93 | @param successCallback 成功回调 94 | @param errorCallback 失败回调 95 | */ 96 | +(void)delAccount:(nullable void(^)(void)) successCallback errorCallback:(nullable void(^)(void)) errorCallback; 97 | 98 | /** 99 | 设置 tag 100 | 101 | @param tag 需要设置的 tag 102 | @param successCallback 成功回调 103 | @param errorCallback 失败回调 104 | */ 105 | +(void)setTag:(nonnull NSString *)tag successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 106 | 107 | 108 | /** 109 | 删除tag 110 | 111 | @param tag 需要删除的 tag 112 | @param successCallback 成功回调 113 | @param errorCallback 失败回调 114 | */ 115 | +(void)delTag:(nonnull NSString *)tag successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 116 | 117 | /** 118 | 在didFinishLaunchingWithOptions中调用,用于推送反馈.(app没有运行时,点击推送启动时) 119 | 120 | @param launchOptions didFinishLaunchingWithOptions中的userinfo参数 121 | @param successCallback 成功回调 122 | @param errorCallback 失败回调 123 | */ 124 | +(void)handleLaunching:(nonnull NSDictionary *)launchOptions successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 125 | 126 | /** 127 | 在didReceiveRemoteNotification中调用,用于推送反馈。(app在运行时) 128 | 129 | @param userInfo 苹果 apns 的推送信息 130 | @param successCallback 成功回调 131 | @param errorCallback 失败回调 132 | */ 133 | +(void)handleReceiveNotification:(nonnull NSDictionary *)userInfo successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback; 134 | 135 | 136 | /** 137 | * 获取userInfo里的bid信息(bid:信鸽的推送消息id) 138 | * @param userInfo 苹果apns的推送信息 139 | * @return none 140 | */ 141 | +(nullable NSString *)getBid:(nonnull NSDictionary *)userInfo; 142 | 143 | /** 144 | * deviceToken类型转换 145 | * @param deviceToken NSData格式的deviceToken 146 | * @return none 147 | */ 148 | +(nullable NSString *)getDeviceToken:(nonnull NSData *)deviceToken; 149 | 150 | 151 | // 以下接口已经不在维护,请尽快替换 152 | +(void)localNotification:(nonnull NSDate *)fireDate alertBody:(nonnull NSString *)alertBody badge:(int)badge alertAction:(nonnull NSString *)alertAction userInfo:(nonnull NSDictionary *)userInfo DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用苹果提供的 API 删除本地推送"); 153 | +(void)localNotificationAtFrontEnd:(nonnull UILocalNotification *)notification userInfoKey:(nonnull NSString *)userInfoKey userInfoValue:(nonnull NSString *)userInfoValue DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,若需要弹窗,请用 AlertViewController 手动弹出"); 154 | +(void)delLocalNotification:(nonnull NSString *)userInfoKey userInfoValue:(nonnull NSString *)userInfoValue DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用苹果提供的 API 删除本地推送"); 155 | +(void)delLocalNotification:(nonnull UILocalNotification *)myUILocalNotification DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用苹果提供的 API 删除本地推送"); 156 | +(void)clearLocalNotifications DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用苹果提供的 API 删除本地推送"); 157 | +(uint32_t)getAccessID DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用带回调的方法替代"); 158 | +(void)initForReregister:(nullable void (^)(void)) successCallback DEPRECATED_MSG_ATTRIBUTE("方法已经废弃,请不要使用此方法"); 159 | +(void)setAccount:(nonnull NSString *)account DEPRECATED_MSG_ATTRIBUTE("方法已经废弃,请使用带回调的方法替代"); 160 | +(nullable NSString *)registerDevice:(nonnull NSData *)deviceToken DEPRECATED_MSG_ATTRIBUTE("方法已经废弃,请使用带回调的方法替代"); 161 | +(nullable NSString *)registerDeviceStr:(nonnull NSString *)deviceToken DEPRECATED_MSG_ATTRIBUTE("方法已经废弃,请使用带回调的方法替代"); 162 | +(void)unRegisterDevice DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用带回调的方法替代"); 163 | +(void)setTag:(nonnull NSString *)tag DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用带回调的方法替代"); 164 | +(void)delTag:(nonnull NSString *)tag DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用带回调的方法替代"); 165 | +(void)handleReceiveNotification:(nonnull NSDictionary *)userInfo DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃"); 166 | +(void)handleReceiveNotification:(nonnull NSDictionary *)userInfo completion:(nullable void (^)(void)) completion DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃"); 167 | +(void)handleReceiveNotification:(nonnull NSDictionary *)userInfo successCallback:(nullable void (^)(void)) successCallback errorCallback:(nullable void (^)(void)) errorCallback completion:(nullable void (^)(void)) completion DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃"); 168 | +(void)handleLaunching:(nonnull NSDictionary *)launchOptions DEPRECATED_MSG_ATTRIBUTE("此方法已经废弃,请使用带回调的方法替代"); 169 | 170 | @end 171 | -------------------------------------------------------------------------------- /sdk/ios/demo/sdk/XGSetting.h: -------------------------------------------------------------------------------- 1 | // 2 | // XGSetting.h 3 | // XG-SDK 4 | // 5 | // Created by xiangchen on 29/08/14. 6 | // Copyright (c) 2014 mta. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define XG_SDK_VERSION @"2.5.0" 12 | 13 | @interface XGSetting : NSObject 14 | 15 | @property (nonatomic,retain) NSString* Channel DEPRECATED_MSG_ATTRIBUTE("此属性已经废弃"); 16 | @property (nonatomic,retain) NSString* GameServer DEPRECATED_MSG_ATTRIBUTE("此属性已经废弃"); 17 | 18 | +(id)getInstance; 19 | 20 | -(void) enableDebug:(BOOL) enbaleDebug; 21 | -(BOOL) isEnableDebug; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /sdk/ios/demo/sdk/libXG-SDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ETENG-OSP/xgpush-cordova/e83f5164b2902f7f37ff85c954d8feca0ae180b5/sdk/ios/demo/sdk/libXG-SDK.a -------------------------------------------------------------------------------- /src/android/DiskHeap.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.FilenameFilter; 8 | import java.io.IOException; 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | import java.util.UUID; 12 | 13 | import android.content.Context; 14 | import android.util.Log; 15 | 16 | public class DiskHeap implements FilenameFilter { 17 | 18 | private static final String TAG = "DiskHeap"; 19 | private static final String SUFFIX = ".xgpush"; 20 | private Context context; 21 | 22 | DiskHeap(Context context) { 23 | this.context = context; 24 | } 25 | 26 | public void put(String message) { 27 | Log.d(TAG, "store message"); 28 | String filename = UUID.randomUUID().toString(); 29 | File file; 30 | try { 31 | file = File.createTempFile(filename, SUFFIX, context.getCacheDir()); 32 | FileOutputStream outputStream = new FileOutputStream(file); 33 | outputStream.write(message.getBytes()); 34 | outputStream.close(); 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | public List popAll() { 41 | Log.d(TAG, "retrive message"); 42 | File[] files = context.getCacheDir().listFiles(this); 43 | List result = new LinkedList(); 44 | for (File file: files) { 45 | Log.d(TAG, file.getName()); 46 | try { 47 | FileInputStream inputStream = new FileInputStream(file); 48 | int length = (int) file.length(); 49 | byte[] buffer = new byte[length]; 50 | inputStream.read(buffer); 51 | inputStream.close(); 52 | result.add(new String(buffer)); 53 | file.delete(); 54 | } catch (FileNotFoundException e) { 55 | e.printStackTrace(); 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | return result; 61 | } 62 | 63 | @Override 64 | public boolean accept(File dir, String filename) { 65 | return filename.endsWith(SUFFIX); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/android/PushPlugin.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.cordova.CallbackContext; 6 | import org.apache.cordova.CordovaInterface; 7 | import org.apache.cordova.CordovaPlugin; 8 | import org.apache.cordova.CordovaWebView; 9 | import org.json.JSONArray; 10 | import org.json.JSONException; 11 | import org.json.JSONObject; 12 | 13 | import android.app.Activity; 14 | import android.content.Context; 15 | import android.content.Intent; 16 | import android.util.Log; 17 | 18 | public abstract class PushPlugin extends CordovaPlugin { 19 | 20 | public static final String TAG = "PushPlugin"; 21 | public static final String ACTION_ENABLE_DEBUG = "enable_debug"; 22 | public static final String ACTION_REGISTER_PUSH = "register_push"; 23 | public static final String ACTION_REGISTER_ACCOUNT = "register_action"; 24 | public static final String ACTION_UNREGISTER_PUSH = "unregister_push"; 25 | public static final String ACTION_SET_TAG = "set_tag"; 26 | public static final String ACTION_DELETE_TAG = "delete_tag"; 27 | public static final String ACTION_CLEAR_CACHE = "clear_cache"; 28 | public static final String ACTION_SET_ID_AND_KEY = "set_id_and_key"; 29 | 30 | public static final String ACTION_READY = "ready"; 31 | 32 | private static CordovaWebView appView; 33 | private static DiskHeap messageCache; 34 | private static boolean safeToFireMessages = false; 35 | 36 | @Override 37 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 38 | Context context = cordova.getActivity().getApplicationContext(); 39 | safeToFireMessages = false; 40 | appView = webView; 41 | messageCache = new DiskHeap(context); 42 | onInitialize(context); 43 | 44 | super.initialize(cordova, webView); 45 | } 46 | 47 | @Override 48 | public void onPause(boolean multitasking) { 49 | safeToFireMessages = false; 50 | this.onActivityPause(this.cordova.getActivity()); 51 | super.onPause(multitasking); 52 | } 53 | 54 | @Override 55 | public void onResume(boolean multitasking) { 56 | this.onActivityResume(this.cordova.getActivity()); 57 | super.onResume(multitasking); 58 | } 59 | 60 | @Override 61 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 62 | Log.d(TAG, "receive action " + action); 63 | Context context = this.cordova.getActivity(); 64 | 65 | if (action.equals(ACTION_REGISTER_PUSH)) { 66 | this.onRegisterPush(context); 67 | 68 | } else if (action.equals(ACTION_REGISTER_ACCOUNT)) { 69 | String account = args.getString(0); 70 | this.onRegisterAccount(context, account); 71 | 72 | } else if (action.equals(ACTION_SET_TAG)) { 73 | String tag = args.getString(0); 74 | this.onSetTag(context, tag); 75 | 76 | } else if (action.equals(ACTION_DELETE_TAG)) { 77 | String tag = args.getString(0); 78 | this.onDeleteTag(context, tag); 79 | 80 | } else if (action.equals(ACTION_UNREGISTER_PUSH)) { 81 | this.onUnregisterPush(context); 82 | 83 | } else if (action.equals(ACTION_CLEAR_CACHE)) { 84 | this.onClearCache(context); 85 | 86 | } else if (action.equals(ACTION_ENABLE_DEBUG)) { 87 | boolean enable = args.getBoolean(0); 88 | this.onEnableDebug(context, enable); 89 | 90 | } else if (ACTION_SET_ID_AND_KEY.equals(action)) { 91 | long id = args.getLong(0); 92 | String key = args.getString(1); 93 | this.onSetIdAndKey(context, id, key); 94 | 95 | } else if (ACTION_READY.equals(action)) { 96 | this.onReady(); 97 | } 98 | 99 | return false; 100 | } 101 | 102 | private void onReady() { 103 | safeToFireMessages = true; 104 | List pending = messageCache.popAll(); 105 | for (String message: pending) { 106 | fireMessage(message); 107 | } 108 | } 109 | 110 | public static void handlePushMessage(Context context, Intent intent) { 111 | JSONObject payload = new JSONObject(); 112 | try { 113 | for (String key : intent.getExtras().keySet()) { 114 | payload.put(key, intent.getStringExtra(key)); 115 | } 116 | } catch (Exception e) { 117 | Log.e(TAG, "Error construction push message payload: " + e); 118 | return; 119 | } 120 | String payloadString = payload.toString(); 121 | 122 | if (!safeToFireMessages || appView == null) { 123 | messageCache.put(payloadString); 124 | return; 125 | } 126 | 127 | fireMessage(payloadString); 128 | } 129 | 130 | private static void fireMessage(String message) { 131 | appView.sendJavascript(message); 132 | } 133 | 134 | protected abstract void onActivityPause(Activity context); 135 | protected abstract void onActivityResume(Activity context); 136 | 137 | protected abstract void onEnableDebug(Context context, boolean enable); 138 | protected abstract void onRegisterPush(Context context); 139 | protected abstract void onRegisterAccount(Context context, String account); 140 | protected abstract void onUnregisterPush(Context context); 141 | protected abstract void onSetTag(Context context, String tag); 142 | protected abstract void onDeleteTag(Context context, String tag); 143 | protected abstract void onClearCache(Context context); 144 | protected abstract void onSetIdAndKey(Context context, long id, String key); 145 | protected abstract void onInitialize(Context applicationContext); 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/android/XGPush.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | 6 | import com.tencent.android.tpush.XGPushConfig; 7 | import com.tencent.android.tpush.XGPushManager; 8 | import com.tencent.android.tpush.horse.Tools; 9 | 10 | public class XGPush extends PushPlugin { 11 | 12 | @Override 13 | protected void onInitialize(Context context) { 14 | XGPushConfig.enableDebug(context, true); 15 | XGPushManager.registerPush(context); 16 | } 17 | 18 | @Override 19 | protected void onEnableDebug(Context context, boolean enable) { 20 | XGPushConfig.enableDebug(context, enable); 21 | } 22 | 23 | @Override 24 | protected void onRegisterPush(Context context) { 25 | XGPushManager.registerPush(context); 26 | } 27 | 28 | @Override 29 | protected void onRegisterAccount(Context context, String account) { 30 | XGPushManager.registerPush(context, account); 31 | } 32 | 33 | @Override 34 | protected void onUnregisterPush(Context context) { 35 | XGPushManager.unregisterPush(context); 36 | } 37 | 38 | @Override 39 | protected void onSetTag(Context context, String tag) { 40 | XGPushManager.setTag(context, tag); 41 | } 42 | 43 | @Override 44 | protected void onDeleteTag(Context context, String tag) { 45 | XGPushManager.deleteTag(context, tag); 46 | } 47 | 48 | @Override 49 | protected void onClearCache(Context context) { 50 | Tools.clearCacheServerItems(context); 51 | Tools.clearOptStrategyItem(context); 52 | } 53 | 54 | @Override 55 | protected void onActivityPause(Activity activity) { 56 | XGPushManager.onActivityStoped(activity); 57 | } 58 | 59 | @Override 60 | protected void onActivityResume(Activity activity) { 61 | XGPushManager.onActivityStarted(activity); 62 | } 63 | 64 | @Override 65 | protected void onSetIdAndKey(Context context, long id, String key) { 66 | XGPushConfig.setAccessId(context, id); 67 | XGPushConfig.setAccessKey(context, key); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/android/XGReceiver.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | import com.tencent.android.tpush.XGPushBaseReceiver; 7 | import com.tencent.android.tpush.XGPushClickedResult; 8 | import com.tencent.android.tpush.XGPushRegisterResult; 9 | import com.tencent.android.tpush.XGPushShowedResult; 10 | import com.tencent.android.tpush.XGPushTextMessage; 11 | 12 | public class XGReceiver extends XGPushBaseReceiver { 13 | 14 | public static final String TAG = "XGReceiver"; 15 | 16 | @Override 17 | public void onTextMessage(Context context, XGPushTextMessage message) { 18 | Intent intent = new Intent(); 19 | intent.putExtra("Title", message.getTitle()); 20 | intent.putExtra("Content", message.getContent()); 21 | 22 | PushPlugin.handlePushMessage(context, intent); 23 | } 24 | 25 | @Override 26 | public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult registerMessage) { 27 | } 28 | 29 | @Override 30 | public void onUnregisterResult(Context context, int errorCode) { 31 | } 32 | 33 | @Override 34 | public void onSetTagResult(Context context, int errorCode, String tagName) { 35 | } 36 | 37 | @Override 38 | public void onDeleteTagResult(Context context, int errorCode, String tagName) { 39 | } 40 | 41 | @Override 42 | public void onNotifactionClickedResult(Context context, XGPushClickedResult message) { 43 | } 44 | 45 | @Override 46 | public void onNotifactionShowedResult(Context context, XGPushShowedResult notifiShowedRlt) { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/android/v2/ReceiverManager.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush2; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | 5 | import com.tencent.android.tpush.XGPushConstants; 6 | 7 | import android.content.BroadcastReceiver; 8 | import android.content.Context; 9 | import android.content.IntentFilter; 10 | 11 | public class ReceiverManager { 12 | 13 | protected boolean registerReceiver(Context context, CallbackContext callback) { 14 | BroadcastReceiver receiver = new XGCordovaPushReceiver(callback); 15 | IntentFilter filter = new IntentFilter(); 16 | filter.addAction(XGPushConstants.ACTION_PUSH_MESSAGE); 17 | filter.addAction(XGPushConstants.ACTION_FEEDBACK); 18 | context.registerReceiver(receiver, filter); 19 | return true; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/android/v2/XGCordova.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush2; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | 5 | import com.tencent.android.tpush.XGIOperateCallback; 6 | import com.tencent.android.tpush.XGPushManager; 7 | 8 | import android.content.Context; 9 | import android.text.TextUtils; 10 | import android.util.Log; 11 | 12 | public class XGCordova extends XGPushPlugin { 13 | 14 | private static final String TAG = "XGCordovaPlugin"; 15 | private ReceiverManager manager = new ReceiverManager(); 16 | 17 | @Override 18 | protected boolean registerPush(Context context, String alias, CallbackContext callback) { 19 | Log.d(TAG, "> register: " + alias); 20 | XGIOperateCallback reply = new XGCordovaOperateCallback(callback); 21 | if (TextUtils.isEmpty(alias)) { 22 | Log.d(TAG, "> register public"); 23 | XGPushManager.registerPush(context, reply); 24 | } else { 25 | Log.d(TAG, "> register private"); 26 | XGPushManager.registerPush(context, alias, reply); 27 | } 28 | 29 | return true; 30 | } 31 | 32 | @Override 33 | protected boolean unregisterPush(Context context, CallbackContext callback) { 34 | XGIOperateCallback reply = new XGCordovaOperateCallback(callback); 35 | XGPushManager.unregisterPush(context, reply); 36 | return true; 37 | } 38 | 39 | @Override 40 | protected boolean addListener(Context context, CallbackContext callback) { 41 | return manager.registerReceiver(context, callback); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/android/v2/XGCordovaOperateCallback.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush2; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | import com.tencent.android.tpush.XGIOperateCallback; 8 | 9 | public class XGCordovaOperateCallback implements XGIOperateCallback { 10 | 11 | private CallbackContext callback; 12 | 13 | XGCordovaOperateCallback(CallbackContext callback) { 14 | this.callback = callback; 15 | } 16 | 17 | @Override 18 | public void onFail(Object data, int errCode, String msg) { 19 | JSONObject results = new JSONObject(); 20 | try { 21 | results.put("data", data); 22 | results.put("code", errCode); 23 | results.put("message", msg); 24 | } catch (JSONException e) { 25 | e.printStackTrace(); 26 | } 27 | this.callback.error(results); 28 | } 29 | 30 | @Override 31 | public void onSuccess(Object data, int flag) { 32 | JSONObject results = new JSONObject(); 33 | try { 34 | results.put("data", data); 35 | results.put("flag", flag); 36 | } catch (JSONException e) { 37 | e.printStackTrace(); 38 | } 39 | this.callback.success(results); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/android/v2/XGCordovaPushReceiver.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush2; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | import org.apache.cordova.PluginResult; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | import android.content.Context; 9 | 10 | import com.tencent.android.tpush.XGPushBaseReceiver; 11 | import com.tencent.android.tpush.XGPushClickedResult; 12 | import com.tencent.android.tpush.XGPushRegisterResult; 13 | import com.tencent.android.tpush.XGPushShowedResult; 14 | import com.tencent.android.tpush.XGPushTextMessage; 15 | 16 | public class XGCordovaPushReceiver extends XGPushBaseReceiver { 17 | 18 | private CallbackContext callback; 19 | 20 | public XGCordovaPushReceiver(CallbackContext callback) { 21 | this.callback = callback; 22 | } 23 | 24 | @Override 25 | public void onDeleteTagResult(Context arg0, int arg1, String arg2) { 26 | } 27 | 28 | @Override 29 | public void onNotifactionClickedResult(Context arg0, XGPushClickedResult arg1) { 30 | } 31 | 32 | @Override 33 | public void onNotifactionShowedResult(Context arg0, XGPushShowedResult arg1) { 34 | } 35 | 36 | @Override 37 | public void onRegisterResult(Context arg0, int arg1, XGPushRegisterResult arg2) { 38 | } 39 | 40 | @Override 41 | public void onSetTagResult(Context arg0, int arg1, String arg2) { 42 | } 43 | 44 | @Override 45 | public void onTextMessage(Context arg0, XGPushTextMessage message) { 46 | JSONObject data = new JSONObject(); 47 | try { 48 | data.put("content", message.getContent()); 49 | data.put("title", message.getTitle()); 50 | data.put("customContent", message.getCustomContent()); 51 | } catch (JSONException e) { 52 | e.printStackTrace(); 53 | } 54 | PluginResult results = new PluginResult(PluginResult.Status.OK, data); 55 | results.setKeepCallback(true); 56 | this.callback.sendPluginResult(results); 57 | } 58 | 59 | @Override 60 | public void onUnregisterResult(Context arg0, int arg1) { 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/android/v2/XGPushPlugin.java: -------------------------------------------------------------------------------- 1 | package com.eteng.push.xgpush2; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | import org.apache.cordova.CordovaPlugin; 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.util.Log; 11 | 12 | public abstract class XGPushPlugin extends CordovaPlugin { 13 | 14 | private static final String TAG = "XGCordovaPlugin"; 15 | private static final String ACTION_REGISTER_PUSH = "registerpush"; 16 | private static final String ACTION_UNREGISTER_PUSH = "unregisterpush"; 17 | private static final String ACTION_ADD_LISTENER = "addlistener"; 18 | 19 | abstract protected boolean registerPush(Context context, String alias, CallbackContext callback); 20 | abstract protected boolean unregisterPush(Context context, CallbackContext callback); 21 | abstract protected boolean addListener(Context context, CallbackContext callback); 22 | 23 | @Override 24 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 25 | Log.d(TAG, "> plugin invoke"); 26 | Context context = cordova.getActivity().getApplicationContext(); 27 | 28 | if (ACTION_REGISTER_PUSH.equals(action)) { 29 | String alias = args.getString(0); 30 | return registerPush(context, alias, callbackContext); 31 | 32 | } else if (ACTION_UNREGISTER_PUSH.equals(action)) { 33 | return unregisterPush(context, callbackContext); 34 | 35 | } else if (ACTION_ADD_LISTENER.equals(action)) { 36 | return addListener(context, callbackContext); 37 | 38 | } 39 | 40 | return false; 41 | } 42 | 43 | /** 44 | * fix for singletop 45 | */ 46 | @Override 47 | public void onNewIntent(Intent intent) { 48 | super.onNewIntent(intent); 49 | this.cordova.getActivity().setIntent(intent); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/ios/AppDelegate+CDVXGPush.h: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import 3 | 4 | @interface AppDelegate (CDVXGPush) 5 | @end 6 | -------------------------------------------------------------------------------- /src/ios/AppDelegate+CDVXGPush.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate+CDVXGPush.h" 2 | 3 | @implementation AppDelegate (CDVXGPush) 4 | 5 | /** 6 | * 追加推送事件 7 | */ 8 | - (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { 9 | NSLog(@"[AppDelegate] receive remote notification"); 10 | [[NSNotificationCenter defaultCenter] postNotificationName: @"receivenotification" object:userInfo]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /src/ios/CDVRegisterNotification.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface CDVRegisterNotification : NSObject 4 | 5 | + (void) registerPush; 6 | + (void) registerPushForIOS8; 7 | + (void) registerNotification; 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /src/ios/CDVRegisterNotification.m: -------------------------------------------------------------------------------- 1 | #import "CDVRegisterNotification.h" 2 | 3 | @implementation CDVRegisterNotification 4 | 5 | + (void) registerNotification 6 | { 7 | NSLog(@"[CDVRegisterNotification] register notification"); 8 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ 9 | // iOS8注册push方法 10 | float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; 11 | if (sysVer < 8) { 12 | [CDVRegisterNotification registerPush]; 13 | } else { 14 | [CDVRegisterNotification registerPushForIOS8]; 15 | } 16 | #else 17 | // iOS8之前注册push方法 18 | // 注册Push服务,注册后才能收到推送 19 | [CDVRegisterNotification registerPush]; 20 | #endif 21 | } 22 | 23 | + (void) registerPush 24 | { 25 | NSLog(@"[CDVRegisterNotification] register under ios 8"); 26 | [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 27 | } 28 | 29 | + (void) registerPushForIOS8 30 | { 31 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ 32 | NSLog(@"[CDVRegisterNotification] register ios 8"); 33 | 34 | //Types 35 | UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 36 | 37 | //Actions 38 | UIMutableUserNotificationAction* acceptAction = [[UIMutableUserNotificationAction alloc] init]; 39 | 40 | acceptAction.identifier = @"ACCEPT_IDENTIFIER"; 41 | acceptAction.title = @"Accept"; 42 | 43 | acceptAction.activationMode = UIUserNotificationActivationModeForeground; 44 | acceptAction.destructive = NO; 45 | acceptAction.authenticationRequired = NO; 46 | 47 | //Categories 48 | UIMutableUserNotificationCategory* inviteCategory = [[UIMutableUserNotificationCategory alloc] init]; 49 | 50 | inviteCategory.identifier = @"INVITE_CATEGORY"; 51 | 52 | [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault]; 53 | 54 | [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal]; 55 | 56 | // using arc 57 | // [acceptAction release]; 58 | 59 | NSSet* categories = [NSSet setWithObjects:inviteCategory, nil]; 60 | 61 | // using arc 62 | // [inviteCategory release]; 63 | 64 | UIUserNotificationSettings* mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; 65 | 66 | [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 67 | 68 | [[UIApplication sharedApplication] registerForRemoteNotifications]; 69 | #endif 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /src/ios/CDVXGPushPlugin.h: -------------------------------------------------------------------------------- 1 | #import "CDVXGPushUtil.h" 2 | #import 3 | #import 4 | 5 | @interface CDVXGPushPlugin: CDVPlugin 6 | 7 | - (void) didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification*)notification; 8 | - (void) didFailToRegisterForRemoteNotificationsWithError:(NSNotification*)notification; 9 | - (void) didReceiveRemoteNotification:(NSNotification*)notification; 10 | 11 | - (void) registerpush:(CDVInvokedUrlCommand*)command; 12 | - (void) unregisterpush:(CDVInvokedUrlCommand*)command; 13 | - (void) addlistener:(CDVInvokedUrlCommand*)command; 14 | 15 | @property CDVXGPushUtil* util; 16 | @property NSMutableArray* callbackIds; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /src/ios/CDVXGPushPlugin.m: -------------------------------------------------------------------------------- 1 | #import "CDVXGPushPlugin.h" 2 | #import "CDVXGPushUtil.h" 3 | 4 | @implementation CDVXGPushPlugin 5 | 6 | /** 7 | * 插件初始化 8 | */ 9 | - (void) pluginInitialize { 10 | // 注册获取 token 回调 11 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRegisterForRemoteNotificationsWithDeviceToken:) name:CDVRemoteNotification object:nil]; 12 | 13 | // 注册错误回调 14 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFailToRegisterForRemoteNotificationsWithError:) name:CDVRemoteNotificationError object:nil]; 15 | 16 | // 注册接收回调 17 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveRemoteNotification:) name:@"receivenotification" object:nil]; 18 | 19 | // 初始化 20 | self.util = [[CDVXGPushUtil alloc] init]; 21 | self.callbackIds = [[NSMutableArray alloc] init]; 22 | 23 | // 启动 XGPush 24 | [self.util startApp]; 25 | [self.util initForReregister]; 26 | } 27 | 28 | /** 29 | * [description] 30 | * 31 | * @param {[type]} void [description] 32 | * @return {[type]} [description] 33 | */ 34 | - (void) didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification*)notification { 35 | NSLog(@"[XGPushPlugin] receive device token: %@", notification.object); 36 | [self.util registerDevice:notification.object]; 37 | } 38 | 39 | /** 40 | * [description] 41 | * 42 | * @param {[type]} void [description] 43 | * @return {[type]} [description] 44 | */ 45 | - (void) didFailToRegisterForRemoteNotificationsWithError:(NSNotification*)notification { 46 | NSLog(@"[XGPushPlugin] register fail"); 47 | } 48 | 49 | /** 50 | * [description] 51 | * 52 | * @param {[type]} void [description] 53 | * @return {[type]} [description] 54 | */ 55 | - (void) didReceiveRemoteNotification:(NSNotification*)notification { 56 | NSLog(@"[XGPushPlugin] receive notification: %@", notification); 57 | NSLog(@"[XGPushPlugin] callback ids: %@", self.callbackIds); 58 | [self.callbackIds enumerateObjectsUsingBlock:^(id callbackId, NSUInteger idx, BOOL *stop) { 59 | NSLog(@"[XGPushPlugin] callbackId: %@", callbackId); 60 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:notification.object]; 61 | [result setKeepCallback:[NSNumber numberWithBool:YES]]; 62 | [self.commandDelegate sendPluginResult:result callbackId:callbackId]; 63 | }]; 64 | } 65 | 66 | /** 67 | * [description] 68 | * 69 | * @param {[type]} void [description] 70 | * @return {[type]} [description] 71 | */ 72 | - (void) registerpush:(CDVInvokedUrlCommand*)command { 73 | NSString* alias = [command.arguments objectAtIndex:0]; 74 | NSLog(@"[XGPushPlugin] registerpush: %@", alias); 75 | 76 | // FIXME: 放到 background thread 里运行时无法执行回调 77 | [self.util registerPush:alias successCallback:^{ 78 | // 成功 79 | NSLog(@"[XGPushPlugin] registerpush success"); 80 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 81 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 82 | 83 | } errorCallback:^{ 84 | // 失败 85 | NSLog(@"[XGPushPlugin] registerpush error"); 86 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; 87 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 88 | }]; 89 | } 90 | 91 | /** 92 | * [description] 93 | * 94 | * @param {[type]} void [description] 95 | * @return {[type]} [description] 96 | */ 97 | - (void) unregisterpush:(CDVInvokedUrlCommand*)command { 98 | NSLog(@"[XGPushPlugin] registerpush"); 99 | 100 | // FIXME: 放到 background thread 里运行时无法执行回调 101 | [self.util unregisterPush:^{ 102 | // 成功 103 | NSLog(@"[XGPushPlugin] deregisterpush success"); 104 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 105 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 106 | 107 | } errorCallback:^{ 108 | // 失败 109 | NSLog(@"[XGPushPlugin] deregisterpush error"); 110 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; 111 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 112 | 113 | }]; 114 | } 115 | 116 | /** 117 | * [description] 118 | * 119 | * @param {[type]} void [description] 120 | * @return {[type]} [description] 121 | */ 122 | - (void) addlistener:(CDVInvokedUrlCommand*)command { 123 | NSLog(@"[XGPushPlugin] add listener: %@", command.callbackId); 124 | [self.callbackIds addObject:command.callbackId]; 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /src/ios/CDVXGPushUtil.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | typedef void (^CallbackBlock)(void); 4 | 5 | @interface CDVXGPushUtil: NSObject 6 | 7 | - (void) startApp; 8 | - (void) initForReregister; 9 | - (void) registerDevice:(NSData*)deviceToken; 10 | - (void) registerPush:(NSString*)alias successCallback:(CallbackBlock)success errorCallback:(CallbackBlock)error; 11 | - (void) unregisterPush:(CallbackBlock)success errorCallback:(CallbackBlock)error; 12 | - (uint32_t) getAccessID; 13 | - (NSString*) getAccessKey; 14 | 15 | @property NSData* deviceToken; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /src/ios/CDVXGPushUtil.m: -------------------------------------------------------------------------------- 1 | #import "CDVXGPushUtil.h" 2 | #import "CDVRegisterNotification.h" 3 | #import "XGPush.h" 4 | 5 | @implementation CDVXGPushUtil 6 | 7 | /** 8 | * 注册通知 9 | */ 10 | - (void) initForReregister { 11 | NSLog(@"[XGPush] init for re-register"); 12 | [XGPush initForReregister:^{ 13 | // 如果变成需要注册状态 14 | if (![XGPush isUnRegisterStatus]) { 15 | [CDVRegisterNotification registerNotification]; 16 | } 17 | }]; 18 | } 19 | 20 | /** 21 | * 启动 xgpush 22 | */ 23 | - (void) startApp { 24 | uint32_t accessID = [self getAccessID]; 25 | NSString* accessKey = [self getAccessKey]; 26 | NSLog(@"[XGPush] starting with access id: %u, access key: %@", accessID, accessKey); 27 | [XGPush startApp:accessID appKey:accessKey]; 28 | } 29 | 30 | /** 31 | * 记录 device token 32 | * 33 | * @param {NSData*} deviceToken [description] 34 | * @return {[type]} [description] 35 | */ 36 | - (void) registerDevice:(NSData*)deviceToken { 37 | NSLog(@"[XGPush] register with token:%@", deviceToken); 38 | self.deviceToken = deviceToken; 39 | } 40 | 41 | /** 42 | * 注册 xgpush 43 | * 44 | * @param {[type]} void [description] 45 | * @return {[type]} [description] 46 | */ 47 | - (void) registerPush:(NSString*)alias successCallback:(CallbackBlock)success errorCallback:(CallbackBlock)error { 48 | NSLog(@"[XGPush] register with token:%@ alias:%@", self.deviceToken, alias); 49 | if ([alias respondsToSelector:@selector(length)] && [alias length] > 0) { 50 | NSLog(@"[XGPush] setting alias:%@", alias); 51 | [XGPush setAccount:alias]; 52 | } 53 | 54 | [XGPush registerDevice:self.deviceToken successCallback:success errorCallback:error]; 55 | } 56 | 57 | /** 58 | * 停止接收 59 | */ 60 | - (void)unregisterPush:(CallbackBlock)success errorCallback:(CallbackBlock)error { 61 | [XGPush unRegisterDevice:success errorCallback:error]; 62 | } 63 | 64 | /** 65 | * 获取 access id 66 | * 67 | * @param {[type]} uint32_t [description] 68 | * @return {[type]} [description] 69 | */ 70 | - (uint32_t) getAccessID { 71 | return [[[[NSBundle mainBundle] objectForInfoDictionaryKey:@"XGPushMeta"] valueForKey:@"AccessID"] intValue]; 72 | } 73 | 74 | /** 75 | * 获取 access key 76 | * 77 | * @param {[type]} NSString* [description] 78 | * @return {[type]} [description] 79 | */ 80 | - (NSString*) getAccessKey { 81 | return [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"XGPushMeta"] valueForKey:@"AccessKey"]; 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /tutorial/README.md: -------------------------------------------------------------------------------- 1 | ../README.md -------------------------------------------------------------------------------- /www/xgpush.js: -------------------------------------------------------------------------------- 1 | !function t(e,n,r){function o(s,u){if(!n[s]){if(!e[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var a=n[s]={exports:{}};e[s][0].call(a.exports,function(t){var n=e[s][1][t];return o(n?n:t)},a,a.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s1)for(var n=1;nt;t+=2){var e=et[t],n=et[t+1];e(n),et[t]=void 0,et[t+1]=void 0}z=0}function _(){try{var e=t,n=e("vertx");return Y=n.runOnLoop||n.runOnContext,a()}catch(r){return p()}}function d(){}function y(){return new TypeError("You cannot resolve a promise with itself")}function m(){return new TypeError("A promises callback cannot return that same promise.")}function g(t){try{return t.then}catch(e){return it.error=e,it}}function w(t,e,n,r){try{t.call(e,n,r)}catch(o){return o}}function b(t,e,n){B(function(t){var r=!1,o=w(n,e,function(n){r||(r=!0,e!==n?A(t,n):T(t,n))},function(e){r||(r=!0,O(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,O(t,o))},t)}function E(t,e){e._state===rt?T(t,e._result):e._state===ot?O(t,e._result):P(e,void 0,function(e){A(t,e)},function(e){O(t,e)})}function x(t,e){if(e.constructor===t.constructor)E(t,e);else{var n=g(e);n===it?O(t,it.error):void 0===n?T(t,e):i(n)?b(t,e,n):T(t,e)}}function A(t,e){t===e?O(t,y()):o(e)?x(t,e):T(t,e)}function S(t){t._onerror&&t._onerror(t._result),I(t)}function T(t,e){t._state===nt&&(t._result=e,t._state=rt,0!==t._subscribers.length&&B(I,t))}function O(t,e){t._state===nt&&(t._state=ot,t._result=e,B(S,t))}function P(t,e,n,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=e,o[i+rt]=n,o[i+ot]=r,0===i&&t._state&&B(I,t)}function I(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r,o,i=t._result,s=0;ss;s++)P(r.resolve(t[s]),void 0,e,n);return o}function M(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(d);return A(n,t),n}function D(t){var e=this,n=new e(d);return O(n,t),n}function G(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function q(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function H(t){this._id=ht++,this._state=void 0,this._result=void 0,this._subscribers=[],d!==t&&(i(t)||G(),this instanceof H||q(),L(this,t))}function V(){var t;if("undefined"!=typeof r)t=r;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=t.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(t.Promise=pt)}var F;F=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var Y,X,K,W=F,z=0,B=({}.toString,function(t,e){et[z]=t,et[z+1]=e,z+=2,2===z&&(X?X(v):K())}),J="undefined"!=typeof window?window:void 0,Q=J||{},Z=Q.MutationObserver||Q.WebKitMutationObserver,$="undefined"!=typeof n&&"[object process]"==={}.toString.call(n),tt="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,et=new Array(1e3);K=$?f():Z?l():tt?h():void 0===J&&"function"==typeof t?_():p();var nt=void 0,rt=1,ot=2,it=new C,st=new C;N.prototype._validateInput=function(t){return W(t)},N.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},N.prototype._init=function(){this._result=new Array(this.length)};var ut=N;N.prototype._enumerate=function(){for(var t=this,e=t.length,n=t.promise,r=t._input,o=0;n._state===nt&&e>o;o++)t._eachEntry(r[o],o)},N.prototype._eachEntry=function(t,e){var n=this,r=n._instanceConstructor;s(t)?t.constructor===r&&t._state!==nt?(t._onerror=null,n._settledAt(t._state,e,t._result)):n._willSettleAt(r.resolve(t),e):(n._remaining--,n._result[e]=t)},N.prototype._settledAt=function(t,e,n){var r=this,o=r.promise;o._state===nt&&(r._remaining--,t===ot?O(o,n):r._result[e]=n),0===r._remaining&&T(o,r._result)},N.prototype._willSettleAt=function(t,e){var n=this;P(t,void 0,function(t){n._settledAt(rt,e,t)},function(t){n._settledAt(ot,e,t)})};var ct=U,ft=k,at=M,lt=D,ht=0,pt=H;H.all=ct,H.race=ft,H.resolve=at,H.reject=lt,H._setScheduler=u,H._setAsap=c,H._asap=B,H.prototype={constructor:H,then:function(t,e){var n=this,r=n._state;if(r===rt&&!t||r===ot&&!e)return this;var o=new this.constructor(d),i=n._result;if(r){var s=arguments[r-1];B(function(){j(r,o,s,i)})}else P(n,o,t,e);return o},"catch":function(t){return this.then(null,t)}};var vt=V,_t={Promise:pt,polyfill:vt};"function"==typeof define&&define.amd?define(function(){return _t}):"undefined"!=typeof e&&e.exports?e.exports=_t:"undefined"!=typeof this&&(this.ES6Promise=_t),vt()}).call(this)}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:1}],4:[function(t,e){"use strict";function n(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function r(){}var o="function"!=typeof Object.create?"~":!1;r.prototype._events=void 0,r.prototype.listeners=function(t,e){var n=o?o+t:t,r=this._events&&this._events[n];if(e)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var i=0,s=r.length,u=new Array(s);s>i;i++)u[i]=r[i].fn;return u},r.prototype.emit=function(t,e,n,r,i,s){var u=o?o+t:t;if(!this._events||!this._events[u])return!1;var c,f,a=this._events[u],l=arguments.length;if("function"==typeof a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,r),!0;case 5:return a.fn.call(a.context,e,n,r,i),!0;case 6:return a.fn.call(a.context,e,n,r,i,s),!0}for(f=1,c=new Array(l-1);l>f;f++)c[f-1]=arguments[f];a.fn.apply(a.context,c)}else{var h,p=a.length;for(f=0;p>f;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,e);break;case 3:a[f].fn.call(a[f].context,e,n);break;default:if(!c)for(h=1,c=new Array(l-1);l>h;h++)c[h-1]=arguments[h];a[f].fn.apply(a[f].context,c)}}return!0},r.prototype.on=function(t,e,r){var i=new n(e,r||this),s=o?o+t:t;return this._events||(this._events=o?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],i]:this._events[s].push(i):this._events[s]=i,this},r.prototype.once=function(t,e,r){var i=new n(e,r||this,!0),s=o?o+t:t;return this._events||(this._events=o?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],i]:this._events[s].push(i):this._events[s]=i,this},r.prototype.removeListener=function(t,e,n,r){var i=o?o+t:t;if(!this._events||!this._events[i])return this;var s=this._events[i],u=[];if(e)if(s.fn)(s.fn!==e||r&&!s.once||n&&s.context!==n)&&u.push(s);else for(var c=0,f=s.length;f>c;c++)(s[c].fn!==e||r&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);return u.length?this._events[i]=1===u.length?u[0]:u:delete this._events[i],this},r.prototype.removeAllListeners=function(t){return this._events?(t?delete this._events[o?o+t:t]:this._events=o?{}:Object.create(null),this):this},r.prototype.off=r.prototype.removeListener,r.prototype.addListener=r.prototype.on,r.prototype.setMaxListeners=function(){return this},r.prefixed=o,"undefined"!=typeof e&&(e.exports=r)},{}]},{},[2]); 2 | var XGPush = window._XGPush; 3 | delete window._XGPush; 4 | module.exports = new XGPush(require('cordova/exec')); 5 | --------------------------------------------------------------------------------