Skip to content

Rich Push Notifications

Andras Sarro edited this page Jan 30, 2023 · 8 revisions

Contents

What is Rich Notification?

Push notification could show media content and action buttons besides the title and body. Push notifications with these types of contents are called Rich Notifications.

Requirements

  1. Mobile Engage backend is setup for sending push notifications already
  2. application is setup for receiving push notifications already
  3. use Emarsys SDK notification extension as mentioned in documentation

Restrictions and limitations

Note

Only HTTPS image URLs are supported.

Mode Text Image
Notification center collapsed Title is 1 line and it’s truncated if too long. Character limit ~ 32. Body is 4 line and it’s truncated if too long. Character limit ~ 175 without picture. The small image preview is shown on the right side. Title: 1 line and it’s truncated if too long. Character limit ~ 32. Body: 4 line and it’s truncated if too long. Character limit ~ 140.
Lockscreen collapsed Title is 1 line and it’s truncated if too long. Character limit ~ 32. Body is 4 line and it’s truncated if too long. Character limit ~ 175 without picture. The small image preview is shown on the right side. Title: 1 line and it’s truncated if too long. Character limit ~ 32. Body: 4 line and it’s truncated if too long. Character limit ~ 140.
Floating collapsed Title is 1 line and it’s truncated if too long. Character limit ~ 32. Body is 4 line and it’s truncated if too long. Character limit ~ 175 without picture. The small image preview is shown on the right side. Title: 1 line and it’s truncated if too long. Character limit ~ 32. Body: 4 line and it’s truncated if too long. Character limit ~ 140.
Expanded Title: 1 line and it’s truncated if too long. If the body is very long then it will be scrollable. Character limitations for title ~ 960 and for the body ~ 174 The image is shown at the bottom. Title is 1 line and it’s truncated if too long. If the body is very long then the notification will be scrollable. The title can be ver long, up to ~1000 characters, the body can be ~256 characters long.

Note

Exceeding text in the expanded message is always cropped, not appearing.

Setup

1. Add a new Notification Service Extension target to your project.
2. Add the EmarsysNotificationService to this target in the Podfile.
`Podfile`
target "Emarsys Sample" do
  pod 'EmarsysSDK'
end

target "EMSNotificationService" do
  pod 'EmarsysNotificationService'
end
3. Install pods with the "pod install" command.
4. If your selected language is Swift, then create a Bridging-Header for your new target.
`<NameOfYourExtension-Bridging-Header.h>`
```swift
#import <EmarsysNotificationService/EMSNotificationService.h>
```
5. Open the NotificationService class in the target, and
* import the EmarsysNotificationService
* extend the class `EMSNotificationService` instead of `UNNotificationServiceExtension`
```swift
import EmarsysNotificationService

class NotificationService: EMSNotificationService {
}
```
6. Request authorization for push notifications in the AppDelegate application:didFinishLaunchingWithOptions: method, like in our sample application
 application.registerForRemoteNotifications()

 var options: UNAuthorizationOptions = [.alert, .sound, .badge]
 UNUserNotificationCenter.current().requestAuthorization(options: options) { [unowned self] granted, error in
     print(granted, error ?? "no error")
     if (granted) {
         Emarsys.notificationCenterDelegate.eventHandler = self
         UNUserNotificationCenter.current().delegate = Emarsys.notificationCenterDelegate
     }
 }
7. Set an EventHandler for Notifications

In order to react to an event, triggered by a push notification message, you have the following options:

  • If you integrate the Emarsys SDK with the EMSAppDelegate, you just have to set the eventHandlerBlock on EMSAppDelegate.
  • Otherwise, you need to set an EMSEventHandlerBlock on Emarsys.push.
Objective-C
Emarsys.push.notificationEventHandler = ^(NSString *eventName, NSDictionary<NSString *, id> *payload) {
        
    };
Swift
Emarsys.push.notificationEventHandler = { eventName, payload in                
}
8. Use other UNUserNotificationCenterDelegate

In case you need to use other UNUserNotificationCenterDelegate solution, you can set that as a delegate to our Emarsys.push.delegate and we call the methods of the delegate when our delegate methods were called.

9. Use EMSNotificationInformationBlock

In case you need information about the received message, you can set your EMSNotificationInformationBlock implementation as a delegate to our Emarsys.push.notificationInformationBlock and we will call the block with a NotificationInformation object.

Objective-C
Emarsys.push.notificationInformationBlock = <Your EMSSilentNotificationInformationBlock>;
Swift
Emarsys.push.notificationInformationBlock = <Your EMSSilentNotificationInformationBlock>
10. That's it. If you are stuck anywhere, just check our sample application.