The nudge library includes support for notifications that include images, which can dramatically increase engagement. For Android integrations, there is nothing to do other than ensure you reference the latest version of the library in the build.gradle file:
releases.com.larky:nudge:4.2.2
For iOS integrations, there are two steps, in addition to ensuring you have the latest version of the library:
4.2.0
Enable basic support for rich notifications
Add extension for rich push notification support
This enables your app to display images in nudges composed in the Larky nudge portal.
Create a new target by going to the menu bar in your Xcode project and selecting File -> New -> Target.
Select Notification Service Extension and give it a name. This can be whatever you want to name it, for example, RichPushExtension.
Once the creation of the extension is completed, Xcode will add a new folder titled with the name of your extension and including the following files in your Project Navigator:
- Info.plist
- NotificationService.swift
Handling rich push notifications
Go to the project root and select the target of the notification service extension you created previously.
Under the General Tab, navigate to the Frameworks and Libraries section and add the Nudge library to your notification service extension target.
In the Project Viewer, navigate to the file NotificationService.swift.
At the top of the file where you place your import statements add the following line:
import NudgeIn the didReceive function add the following code:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
guard let bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) else {
contentHandler(request.content)
return
}
let userInfo = request.content.userInfo
if let isNudge = userInfo["isNudge"] as? Bool, isNudge == true {
Nudge.handleRichPushNotification(request: request, contentHandler: contentHandler)
} else {
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
return
}
We're here to help!
Have questions? Want to schedule time with our technical team to discuss implementation details. Just reach out to us through the Submit a request link above, or email us at support@larky.com.
Comments
0 comments
Article is closed for comments.