Last active
March 29, 2019 15:17
-
-
Save ewieberappc/bc039b8656400534935eb2c1ba8d8706 to your computer and use it in GitHub Desktop.
iOS 12 introduces Notification Grouping, a feature that groups all of the notifications from a single app together in one bundle that prevents the Lock screen from becoming cluttered. This is how you can use it in your app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({ | |
backgroundColor: '#fff' | |
}); | |
var btn = Ti.UI.createButton({ | |
title: 'Schedule Notification' | |
}); | |
btn.addEventListener('click', function() { | |
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"); | |
}); | |
win.add(btn); | |
win.open(); | |
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'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iOS 12 introduces Notification Grouping, a feature that groups all of the notifications from a single app together in one bundle that prevents the Lock screen from becoming cluttered. This is how you can use it in your app. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you happen to know how I could use grouped notifications for push notifications? Is it possible? I cannot find much information about it. I tried to use thread-id as a property in the send push payload, but without much luck. Thanks