-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOSBuilder.js
68 lines (58 loc) · 1.55 KB
/
IOSBuilder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
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
40
41
42
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
/**
* weibo2
* Created by usher.yue.
* User: usher.yue
* Date: 17/12/6
* Time: 22:51
* 心怀教育梦-烟台网格软件技术有限公司
*/
const Message = require('./Message');
const Constants = require('./Constants');
class IOSBuilder extends Message {
constructor() {
super();
this.soundUrl = 'sound_url';
this.badge = 'badge';
}
Description(description) {
this.description = description;
}
timeToLive(ttl) {
this.time_to_live = ttl;
}
timeToSend(timeToSend) {
this.time_to_send = timeToSend;
}
SoundUrl(url) {
this.Extra(IOSBuilder.sound_url, url);
}
Badge(badge) {
this.Extra(IOSBuilder.badge, badge);
}
Extra(key, value) {
this.extra[key] = value;
}
Build() {
let keys = [
'description', 'time_to_live', 'time_to_send'
];
for (let key of keys) {
if (this[key]) {
this.fields[key] = this[key];
this.json_infos[key] = this[key];
}
}
//单独处理extra
let JsonExtra = {};
for (var extraKey in this.extra) {
let extraValue=this.extra[extraKey];
this.fields[Message.EXTRA_PREFIX + extraKey] = extraValue;
JsonExtra[extraKey] = extraValue;
}
this.json_infos['extra'] = JsonExtra;
}
}
/* IOS 使用 */
IOSBuilder.sound_url = 'default'; //可选,消息铃声
IOSBuilder.badge = 0; //可选,自定义通知数字角标
module.exports = IOSBuilder;