Skill Level: Intermediate
This tutorial provides information for iOS action plug-in for enhanced notifications, as well as an action plug-in architectural overview.
Not what youâ€™re looking for? Check out all our available tutorials for mobile app messaging here.
Action plug-ins for enhanced notifications
There are four action plug-ins you can use to enhance your mobile app message:
- Add to Calendar
- Add to Passbook
- Web Action
- iOS image Carousel (For details, see here.)
You can use any of the plug-ins by adding the set of files for the plug-in and registering it. Each plug-in requires certain parameters.
- Add to Calendar plug-inÂ
The Add to Calendar plug-in allows a user to add an event to the calendar. This action happens in the background without opening the calendar.
If the time or timezone fields are incorrect, the timezone of the device is used. You can show the calendar user interface for adding an item to the calendar by adding interactive = true or false in the payload. If false, it does it in the background. Calendar requires AddToCalendarPlugin.h and AddToCalendarPlugin.m.
Note: For iOS 10 applications, add a description to NSCalendarsUsageDescription in the info.plist file that provides a reason to the user for allowing the app to add the calendar event.
- Snooze plug-inÂ
The Snooze plug-in allows a user to bring back the mobile app message after some time.
- Add to Passbook plug-inÂ
The Add to Passbook plug-in allows a user to add a pass to Passbook with a single click.
- Web Action plug-inÂ
The Web Action plug-in allows a mobile app user to view a web page inside the app.
Web Action requires the following files in the plugins/web-action folder: WebActionPlugin.h, WebActionPlugin.m, WebViewController.h, and WebViewController.m. Then, register it in the AppDelegate.
The following example shows how to implement the plug-ins in your AppDelegate init method for iOS:
You can also implement all four plug-ins:
Write your own plug-in
If you want to write your own plug-in, you can adapt the Example plug-in that ships with the SDK. For more information, see Creating custom actions for mobile app messages.
Action plug-in architecture overview
When an action is triggered, the system looks for handlers that match the types registered. You can use two types of action plug-in approaches: simple or advanced.
The simple method consists of modifying the main.m file to point to MCEAppDelegate and setting the AppDelegate class in the configuration file to your AppDelegate class name. When you use this method of integration, the MCEAppDelegate class runs all the required methods at their required integration points and passes over control to all calls back to your AppDelegate class. This works for any custom methods that you want to use because it proxys the callback to the AppDelegate class.
The plug-ins in the sample app are used by following this process. For the simple approach, drag all source files into the project. In the AppDelegate class, add the plug-in initialization code:
You can register any action handlers that you want by implementing the following code.
In the AppDelegate class, add the plug-in initialization code.
Implement the custom action:
You can use an alternative method that includes both the action payload and the rest of the APNs payload:
- In the AppDelegate class, add the plug–in initialization code.
Implement the custom action:
You can create a class that registers with the MCEActionRegistry system as shown in the following example for the WebActionPlugin.h file. The following example overrides the default handling of the url type with a web view inside the application instead of the default handling of opening Safari.
The following example shows the WebActionPlugin.m file.
Register the class in your AppDelegate at launch time, as shown in the following code:
The advanced method involves implementing certain methods on your AppDelegate class instead of using the previous instructions. You must implement the following methods:
Need more help? Check out all of our available tutorials for mobile app messaging here.