Skip to main content

RichView Notification Support

iOS SDK of Diyalog Messaging Platform#

Diyalog SDK is used for enabling messaging for your application. It is a multi-platform communication Messaging SDK for mobile and web. It is easy to integrate, save development cost and delight users with a stable, secure and customization messaging.

Richiew Notificaion Support#

How to add Richview Notification support to your app

Here is the steps for it.

  • Go to project expolrar.

Capabilities

  • Add target -> Select "Notification Content Extension".

Capabilities

  • Give it proper name and press "finish".

Capabilities

  • It will ask for activate to scheme so activate it.

Capabilities

  • Add target -> Select "Notification Service Extension".

Capabilities

  • Give it proper name and press "finish".

Capabilities

  • It will ask for activate to scheme so activate it.

Capabilities

Add DiyalogEngine Framework in both Extension

For that go to project explorar

  • Select NotificationContentExtension target
  • Go "Linked Frameworks and Libraries"
  • Click Add(+) and choose DiyalogEngine.Framework 7.png
  • Same Way add for NotificationServiceExtension 8.png

Select NotificationServiceExtension#

Go to NotificationService.swift and import DiyalogEngine

Replace this method

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
}

With this method

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
// Call method to download notification content
DiyalogEngine.diyalogInstance().didRecieveNotification(bestAttemptContent, withContentHandler: { (attemptContent) in
contentHandler(bestAttemptContent)
})
}
}

Select NotificationContentExtension#

Go to NotificationViewController.swift And

import DiyalogEngine
import AVFoundation

Remove @IBOutlet var label: UILabel?

Replace this method

func didReceive(_ notification: UNNotification) {
}

With this method

func didReceive(_ notification: UNNotification) {
// Call method to load image view or player view
if #available(iOS 10.0, *) {
DiyalogEngine.diyalogInstance().didReceive(notification: notification, superView: self.view) { (uiView, avPlayer, avAudioPlayer) in
if avPlayer != nil {
DispatchQueue.main.async {
avPlayer?.play()
}
} else if avAudioPlayer != nil {
DispatchQueue.main.async {
avAudioPlayer?.play()
}
}
}
} else {
// Fallback on earlier versions
}
}