-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ios.js
executable file
·217 lines (144 loc) · 4.62 KB
/
index.ios.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
127
128
129
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
165
166
167
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
var iOSNativeHelper = require("@nativescript/core").iOSNativeHelper
var scheduler, alarmSupport
function init(){
scheduler = new Scheduler()
alarmSupport = new AlarmSupport()
}
function alarmToJson(alarm){
var dict = AlarmSupport.alarmToDict(alarm)
var component = AlarmSupport.getDateComponents(alarm)
var date = new Date(
component.year,
component.month-1,
component.day,
component.hour,
component.minute,
component.second,
0
)
var keys = iOSNativeHelper.collections.nsArrayToJSArray(dict.allKeys)
var result = {datetime: date, object: alarm}
for(var i in keys) {
var key = keys[i]
var value = dict.objectForKey(key)
result[key] = value
if(key == "alertBody")
result["body"] = value
if(key == "alertTitle")
result["title"] = value
}
return result
}
exports.setUpNotifications = function(params) {
params.alarmSupport.onNotificationReceived = function(alarm){
console.log("onNotificationReceived")
if(params.onNotificationReceived)
params.onNotificationReceived(alarmToJson(alarm))
}
params.alarmSupport.onNotificationClick = function(alarm){
console.log("onNotificationClick")
if(params.onNotificationClick)
params.onNotificationClick(alarmToJson(alarm))
}
params.alarmSupport.onNotificationActionOk = function(alarm){
console.log("onNotificationActionOk")
if(params.onNotificationActionOk)
params.onNotificationActionOk(alarmToJson(alarm))
}
params.alarmSupport.onNotificationActionOpen = function(alarm){
console.log("onNotificationActionOpen")
if(params.onNotificationActionOpen)
params.onNotificationActionOpen(alarmToJson(alarm))
}
params.alarmSupport.onNotificationActionSnooze = function(alarm){
console.log("onNotificationActionSnooze")
if(params.onNotificationActionSnooze)
params.onNotificationActionSnooze(alarmToJson(alarm))
}
AlarmSupport.setUpNotifications(params.alarmSupport)
}
exports.getAlarmSupport = function(){
if(!alarmSupport)
init()
return alarmSupport
}
exports.init = init
// appName, title, text, icon id, extra (json object)
exports.showNotification = function(args){
console.log("## call showNotification")
if(!scheduler)
init()
var alarm = new Alarm()
alarm.id = args.id
alarm.enabled = true
alarm.alertBody = args.body || ""
alarm.alertTitle = args.title || ""
alarm.snoozeInterval = args.snoozeInterval || 15
alarm.soundName = args.soundName || ""
scheduler.show(alarm)
}
exports.cancelNotification = function(args){
console.log("## call cancelNotification")
if(!scheduler)
init()
scheduler.removeNotificaton()
}
exports.cancelAllNotifications = function() {
console.log("## call cancelAllNotifications")
if(!scheduler)
init()
scheduler.removeNotificaton()
}
exports.createAlarm = function(args){
console.log("## call createAlarm")
if(!scheduler)
init()
// createAlarm(String action, Date datetime, int schedulerId, String extraKey, String extraValue)
var swiftDate = AlarmSupport.makeDate(args.datetime.getFullYear(), args.datetime.getMonth()+1, args.datetime.getDate(), args.datetime.getHours(), args.datetime.getMinutes(), args.datetime.getSeconds())
var alarm = new Alarm()
alarm.id = args.id
alarm.date = swiftDate
alarm.alertBody = args.body || ""
alarm.alertTitle = args.title || ""
alarm.soundName = args.soundName || ""
alarm.enabled = true
alarm.snoozeEnabled = args.snoozeEnabled || false
alarm.snoozeInterval = args.snoozeInterval || 15
alarm.buttonOkText = args.buttonOkText || "OK"
alarm.buttonOpenText = args.buttonOpenText || "Abrir"
alarm.buttonSnoozeText = args.buttonSnoozeText || "Sonece"
alarm.now = false
alarm.showButtonOpen = args.showButtonOpen || false
alarm.showButtonOk = args.showButtonOk || false
alarm.showButtonSnooze = args.showButtonSnooze || false
scheduler.schedule(alarm)
}
exports.getAlarms = function () {
console.log("## call getAlarms")
if(!scheduler)
init()
var alarms = scheduler.getAlarms()
var items = []
for(var i = 0; i < alarms.count; i++){
items.push(alarmToJson(alarms[i]))
}
return items
}
exports.cancelAlarm = function(args){
console.log("## call cancelAlarm")
if(!scheduler)
init()
scheduler.cancel(args.id)
}
exports.cancelAllAlarms = function() {
console.log("## call cancelAllAlarms")
if(!scheduler)
init()
scheduler.cancelAll()
}
exports.isAlarmSet = function() {
console.log("## isAlarmSet is not not implemented from ios")
}
exports.requestAuthorization = function(callback){
AlarmSupport.requestAuthorization(callback)
}