Snooze action plugin

The Snooze plugin allows a user to bring back the mobile app message after some time. This action removes the notification from the notification bar and restores it after a number of minutes.

Install the Snooze action plugin

To add the Snooze action plugin, do the following.

  1. In Acoustic Campaign, go to Mobile > Developer Resources > Actions.
  2. From the Actions page, scroll to the iOS actions text area and click New Action.
  3. From the dropdown, select Snooze action, and the template code is automatically added to the iOS actions text area.
  4. Click Save in the top right of the screen before leaving the page.

Enable the Snooze action template

The following example shows how to register the plugins in your AppDelegate method for iOS:

  1. Create a registerPlugins method in the AppDelegate class if one does not already exist.
  2. In the registerPlugins method, add the following code to register the snooze action plugin. The registerPlugins method should be called in the AppDelegate didFinishLaunchingWithOptions method.

🚧

Note:

You must have initialized the SDK before registering the snooze plugin in AppDelegate.

@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self registerPlugins]; // ... } -(void)registerPlugins { [SnoozeActionPlugin registerPlugin]; // ... } @end
class AppDelegate: UIResponder, UIApplicationDelegate { func registerPlugins(){ SnoozeActionPlugin.register() // ... } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication. LaunchOptionsKey : Any]? = nil) -> Bool { registerPlugins() // ... } }

Send an API push with snooze action support

To send a push notification with a snooze 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": "s are delicious", "subtitle": "some subtitle", "body": "somebody" } }, "category-actions": [ { "name": "Snooze notification", "type": "snooze", "value": { "time": 1 }, { "name": "Open app", "type": "openApp" } ] }, "gcm": { "alert": { "subject": "Robits", "message": "s are awesome", "notification-action": { "type": "openApp", "name": "Open App", "value": null } } } } }, "contacts": [ { "channel": { "qualifier": "apxxxxxxxxx", "destination": "wwwwww|yyyyyy" } }, { "channel": { "qualifier": "gcxxxxxxxxx", "destination": "wwwwww|yyyyyy" } } ], "campaignName": "Test Push Notifications" }

Where:

  • 'xxxxxxxxx' – is the value for the channelQualifiers in the payload. Replace it with your specific appKey.
  • 'wwwwww|yyyyyy' – is the destination value in the payload. Replace it with your specific values for userId and channelId.

Android provides snooze support for notifications for Android 8+, with full support in Android 12. In Campaign SDK, 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 Snooze action plug-in using Maven Central. Open the app-level build.gradle file and add the Snooze action plug-in to the Dependencies section.

implementation "io.github.go-acoustic:acoustic-mobile-push-android-snooze:+"

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 Snooze action plug-in.

  1. Go to our plugins directory on Github.
  2. Add acoustic-mobile-push-android-sdk-plugin-snooze.aar to your project's /lib directory and to the build.gradle file.

To install the snooze plugin, run the following command

npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-snooze

📘

Note:

The Snooze plugin is only for iOS, as Android provides snooze support for notifications for Android 8+, with full support in Android 12.

To register the plugin:

  • Import the Acoustic mobile push snooze module to your React component:
  • import { NativeModules, Platform } from 'react-native'; const { // Other Native Modules... RNAcousticMobilePushSnooze, } = NativeModules;
  • Add plugin registration using the SnoozeAction value after the component is mounted.
  • componentDidMount() { if (Platform.OS == 'ios') { // Enable other plugins registration... RNAcousticMobilePushSnooze.registerPlugin("SnoozeAction"); } }

Send an API push with snooze action support.

To send a push notification with a snooze action, send the following to your payload.

{ "campaignName": "iOS Simple Push", "pushes": [ { "userId": "{{userId}}", "simpleMessages": [ { "appKey": "{{appKey}}", "channelId": "{{channelId}}", "content": { "aps": { "alert": { "title": "Testing Snooze", "subtitle": "Test push notification", "body": "Push payload body" }, "sound": "default" }, "category-actions": [ { "name": "Snooze notification", "type": "snooze", "value": { "time": 1 } }, { "name": "Open app", "type": "openApp" } ] } } ] } ] }

Where you must update the {{userId}},{{appKey}}, and {{channelId}} values to match the values in your environment.

To install the snooze plugin, run the following command

cordova plugin add <path to downloaded directory>/plugins/co.acoustic. mobile.push.plugin.snooze cordova prepare

To register the plugin:

@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self registerPlugins]; // ... } -(void)registerPlugins { [SnoozeActionPlugin registerPlugin]; // ... } @end

Send an API push with snooze action support

To send a push notification with a snooze action, send the following to your payload.

{ "campaignName": "iOS Simple Push", "pushes": [ { "userId": "{{userId}}", "simpleMessages": [ { "appKey": "{{appKey}}", "channelId": "{{channelId}}", "content": { "aps": { "alert": { "title": "Testing Snooze", "subtitle": "Test push notification", "body": "Push payload body" }, "sound": "default" }, "category-actions": [ { "name": "Snooze notification", "type": "snooze", "value": { "time": 1 } }, { "name": "Open app", "type": "openApp" } ] } } ] } ] }
update the {{userId}},{{appKey}}, and {{channelId}} values to match the values in your environment.

The snooze data is implemented when the page is initialized.

  1. Add the snooze plug-in to the pubspec.yaml file under dependencies.
flutter_acoustic_mobile_push_snooze: path: ../../plugins/flutter_acoustic_mobile_push_snooze
  1. Go to the SDK zip file and open the plugins folder. Then go to the snooze plugin folder and open the libs folder. From the libs folder, copy the flutter_acoustic_mobile_push_snooze.dart file into your applications libs folder.
  2. Import the snooze plug-in into the dart file.
import 'package:flutter_acoustic_mobile_push_snooze/flutter_acoustic_mobile_push_snooze.dart';

You can now reference the methods within the snooze.dart file.