Skip to content

Commit

Permalink
chore(externalData): fix notification extension service handler
Browse files Browse the repository at this point in the history
  • Loading branch information
worotyns committed Jun 26, 2023
1 parent 47b4e28 commit 44fda03
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions PpgCoreSDK/PpgCoreNotificationServiceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ open class PpgCoreNotificationServiceExtension: UNNotificationServiceExtension {
let dataNotification = NotificationFactory.createData(content: request.content)
let newContent = dataNotification.toUNNotificationMutableContent()
eventService.send(delivered: dataNotification.createDeliveredEvent())
onExternalData(data: dataNotification.externalData)
contentHandler(newContent);
return newContent

case .silent:
PpgCoreLogger.info("Got silent message as normal remote notification");
let silentNotification = NotificationFactory.createSilent(content: request.content)
eventService.send(delivered: silentNotification.createDeliveredEvent())
onExternalData(data: silentNotification.externalData)
let newContent = silentNotification.toUNNotificationMutableContent()
return newContent

Expand All @@ -51,5 +53,9 @@ open class PpgCoreNotificationServiceExtension: UNNotificationServiceExtension {
contentHandler(bestAttemptContent)
}
}

open func onExternalData(data: String) -> Void {

}

}
4 changes: 2 additions & 2 deletions PpgCoreSDK/Services/EventService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class EventService {
}

func internalSend(data: Data, contextId: String, type: EventType, completionHandler: @escaping () -> Void) {
var request = URLRequest(
var request: URLRequest = URLRequest(
url: URL(string: "\(endpoint)/context/\(contextId.lowercased())/events/\(getActionByType(type: type))")!
)

request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = data

URLSession.shared.dataTask(with: request) { data, response, error in
if error != nil {
PpgCoreLogger.info(error?.localizedDescription ?? "Unknown error")
Expand Down
4 changes: 3 additions & 1 deletion examples/sdkdemo/NSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ import UserNotifications
import PpgCoreSDK

class NotificationService: PpgCoreNotificationServiceExtension {

override func onExternalData(data: String) {
PpgCoreLogger.error("NSE RECEIVED EXTERNAL DATA" + data)
}
}
Binary file not shown.

0 comments on commit 44fda03

Please sign in to comment.