Calendar plugin
The Calendar plugin allows a push notification to add an event to the calendar. For this plugin, there are two types of actions:
- The interactive push will open the UI in the app for creating a new event on the calendar with pre-populated fields such as event title, timezone, start date, and end date.
- The non-interactive push will automatically add the event to the calendar with the pre-populated fields as soon as the notification is tapped.
Install the Calendar plugin
To add the calendar action, do the following.
- In Acoustic Campaign, go to Mobile > Developer Resources > Actions.
- From the Actions page, scroll to the iOS actions text area and click New Action.
- From the dropdown, select Calendar action, and the template code is automatically added to the iOS actions text area.
- Click Save in the top right of the screen before leaving the page.
Enable the Calendar plugin template
The following example shows how to register the plugins in your AppDelegate
method for iOS:
- Create a
registerPlugins
method in theAppDelegate
class if one does not already exist. - In the
registerPlugins
method, add the following code to register the calendar plugin. TheregisterPlugins
method should be called in theAppDelegate
didFinishLaunchingWithOptions
method.
Note:
You must have initialized the SDK before registering the calendar plugin in AppDelegate.
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self registerPlugins];
// ...
}
-(void)registerPlugins {
[AddToCalendarPlugin registerPlugin];
// ...
}
@end
class AppDelegate: UIResponder, UIApplicationDelegate {
func registerPlugins(){
AddToCalendarPlugin.register()
// ...
}
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.
LaunchOptionsKey : Any]? = nil) -> Bool {
registerPlugins()
// ...
}
}
Send an API push with calendar action support
To send a push notification with a calendar action, send the following to your payload.
Note:
The following payload is for the push/sends API (/channels/push/sends).
{
"channelQualifiers": [
"gcxxxxxxxxx",
"apxxxxxxxxx"
],
"content": {
"simple": {
"apns": {
"aps": {
"alert": {
"title": "Calendar Action",
"subtitle": "subtitle here",
"body": "subtitle here"
}
},
"notification-action": {
"name": "Calendar",
"type": "calendar",
"value": {
"title": "Event Title",
"timeZone": "PST",
"startDate": "<the event start datetime iso format>",
"endDate": "<the event end datetime iso format>",
"interactive": true
}
}
},
"gcm": {
"alert": {
"subject": "Calendar Action",
"message": "message here",
"notification-action": {
"name": "Calendar",
"type": "calendar",
"starts": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-10",
"time": "12:08"
},
"ends": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-12",
"time": "12:08",
"interactive": true
}
}
}
}
}
},
"contacts": [
{
"channel": {
"qualifier": "apxxxxxxxxx",
"destination": "wwwwww|yyyyyy"
}
},
{
"channel": {
"qualifier": "gcxxxxxxxxx",
"destination": "wwwwww|yyyyyy"
}
}
],
"campaignName": "Test Push Notifications"
}
Where:
'xxxxxxxxx'
– is the value for thechannelQualifiers
in the payload. Replace it with your specificappKey
.-
'wwwwww|yyyyyy'
– is the destination value in the payload. Replace it with your specific values foruserId
andchannelId
.
To get started, you need Android 5.0 (API level 21) or later. Two implementation options are available.
Option A: Automatic (recommended)
If you are using Campaign SDK for Android 3.9.18 or later, you can implement the Calendar plug-in using Maven Central. Open the app-level build.gradle file and add the Calendar plug-in to the Dependencies section.
implementation "io.github.go-acoustic:acoustic-mobile-push-android-calendar:+"
Still using an older version? See Migrate Campaign SDK for Android to version 3.9.18.
Option B: Manual
A manual option is available for all versions of the Calendar plug-in.
- Go to our plugins directory on Github.
- Add acoustic-mobile-push-android-sdk-plugin-calendar.aar to your project's
/lib
directory and to the build.gradle file.
To install the Calendar plugin, run the following command
npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-calendar
Note:
The plugin is available for both Android and iOS platforms.
To register the plugin:
- Import the Acoustic mobile calendar module to your React component:
import { NativeModules, Platform } from 'react-native';
const {
// Other Native Modules...
RNAcousticMobilePushCalendar,
} = NativeModules;
- Add plugin registration using the
CalendarAction
value after the component is mounted.
componentDidMount() {
if (Platform.OS == 'ios') {
// Enable other plugins registration...
RNAcousticMobilePushCalendar.registerPlugin("CalendarAction");
}
}
Send an API push with calendar action support
To send a push notification with a calendar push notification action, send the following to your payload.
{
"campaignName": "Android Simple Push",
"pushes": [
{
"userId": "{{userId}}",
"simpleMessages": [
{
"appKey": "{{appKey}}",
"channelId": "{{channelId}}",
"content": {
"alert": {
"subject": "Calendar Action",
"message": "message here",
"notification-action": {
"name": "Calendar",
"type": "calendar",
"starts": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-10",
"time": "12:08"
},
"ends": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-12",
"time": "12:08",
"interactive": true
}
}
}
}
}
]
}
]
}
{
"campaignName": "iOS Simple Push",
"pushes": [
{
"userId": "{{userId}}",
"simpleMessages": [
{
"appKey": "{{appKey}}",
"channelId": "{{channelId}}",
"content": {
"aps": {
"alert": {
"title": "Testing Calendar",
"subtitle": "Test push notification",
"body": "Push payload body"
},
"sound": "default"
},
"notification-action": {
"type": "calendar",
"name": "Calendar",
"value": {
"title": "Event Title",
"timeZone": "PST",
"startDate": "{{$isoTimestamp}}",
"endDate": "{{$isoTimestamp}}",
"interactive": true
}
}
}
}
]
}
]
}
Where you must update the {{userId}},{{appKey}}, and {{channelId}} values to match the values in your environment.
To install the Calendar plugin, run the following command
cordova plugin add <path to downloaded directory>/plugins/co.acoustic.
mobile.push.plugin.calendar
cordova prepare
Note:
The plugin is available for both Android and iOS platforms.
To register the plugin:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self registerPlugins];
// ...
}
-(void)registerPlugins {
[MCECalendarPlugin pluginInitialize];
// ...
}
@end
Send an API push with calendar action support
To send a push notification with a calendar push notification action, send the following to your payload.
"campaignName": "Android Simple Push",
"pushes": [
{
"userId": "{{userId}}",
"simpleMessages": [
{
"appKey": "{{appKey}}",
"channelId": "{{channelId}}",
"content": {
"alert": {
"subject": "Calendar Action",
"message": "message here",
"notification-action": {
"name": "Calendar",
"type": "calendar",
"starts": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-10",
"time": "12:08"
},
"ends": {
"title": "Event Title",
"timezone": "PST",
"date": "2022-11-12",
"time": "12:08",
"interactive": true
}
}
}
}
}
]
}
]
}
{
"campaignName": "iOS Simple Push",
"pushes": [
{
"userId": "{{userId}}",
"simpleMessages": [
{
"appKey": "{{appKey}}",
"channelId": "{{channelId}}",
"content": {
"aps": {
"alert": {
"title": "Testing Calendar",
"subtitle": "Test push notification",
"body": "Push payload body"
},
"sound": "default"
},
"notification-action": {
"type": "calendar",
"name": "Calendar",
"value": {
"title": "Event Title",
"timeZone": "PST",
"startDate": "{{$isoTimestamp}}",
"endDate": "{{$isoTimestamp}}",
"interactive": true
}
}
}
}
]
}
]
}
Where you must update the {{userId}},{{appKey}}, and {{channelId}} values to match the values in your environment.
The calendar data is implemented when the page is initialized.
- Add the calendar plug-in to the pubspec.yaml file under dependencies.
flutter_acoustic_mobile_push_calendar
path ../../plugins/flutter_acoustic_mobile_push_calendar
- Go to the SDK zip file and open the plugins folder. Then go to the calendar plugin folder and open the libs folder. From the libs folder, copy the
flutter_acoustic_mobile_push_calendar.dart
file into your applications lib folder. - Import the calendar plug-in into the dart file.
import 'package:flutter_acoustic_mobile_push_calendar/flutter_acoustic_mobile_push_calendar.dart';
You can now reference the methods within the calendar.dart file.
Updated 7 months ago