-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupedNotifications.js
81 lines (71 loc) · 2.96 KB
/
groupedNotifications.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
/**
* Docs: https://docs.appcelerator.com/platform/latest/#!/guide/iOS_Interactive_Notifications
*
*/
function btnClk() {
schedule('id_1', 'New Notification', 'These', new Date().getTime() + 3000, "my_thread");
schedule('id_2', 'Another Notification', 'Are', new Date().getTime() + 4000, "my_thread");
schedule('id_3', 'Yet Another Notification', 'Some', new Date().getTime() + 5000, "my_thread");
schedule('id_4', 'One more okay?', 'Pointless', new Date().getTime() + 6000, "other_thread");
schedule('id_5', 'This is the last one', 'Notifications', new Date().getTime() + 7000, "other_thread");
};
function schedule(identifier, title, body, date, thread) {
Ti.App.iOS.scheduleLocalNotification({
identifier: identifier,
alertTitle: title,
alertBody: body,
threadIdentifier: thread,
summaryArgument: 'My Summary',
summaryArgumentCount: 1,
date: date,
category: 'DOWNLOAD_CONTENT'
});
}
var acceptAction = Ti.App.iOS.createUserNotificationAction({
identifier: 'ACCEPT_IDENTIFIER',
title: 'Accept',
activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
destructive: false,
authenticationRequired: true
});
// An action that does not open the app (background action)
var rejectAction = Ti.App.iOS.createUserNotificationAction({
identifier: 'REJECT_IDENTIFIER',
title: 'Reject',
activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
destructive: true,
authenticationRequired: false
});
// An action that does not open the app (background action), but lets the developer
// type in a text (iOS 9+)
var respondAction = Ti.App.iOS.createUserNotificationAction({
identifier: 'RESPOND_IDENTIFIER',
title: 'Respond',
activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
behavior: Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_TEXTINPUT, // or: Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_DEFAULT,
authenticationRequired: false
});
// Create an example notification category
var downloadContent = Ti.App.iOS.createUserNotificationCategory({
identifier: 'DOWNLOAD_CONTENT',
actionsForDefaultContext: [acceptAction, rejectAction, respondAction]
});
// Register for user notifications and categories
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT
],
categories: [downloadContent]
});
// Monitor notifications received while app is in the background
Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
alert('event: localnotificationaction');
});
// Validate notification settings
Ti.App.iOS.addEventListener('usernotificationsettings', function(e) {
Ti.API.info('event: usernotificationsettings');
})
// Monitor notifications received while app is in the foreground
Ti.App.iOS.addEventListener('notification', function(e) {
alert('event: notification');
});