Skip to content

Commit 33d88c9

Browse files
Added delegate that handles rich push from another provider (#625)
* Adding delegate to NotificationServiceExtension to handle multiple providers * Added error handling --------- Co-authored-by: Jay Kim <[email protected]>
1 parent 6d9b979 commit 33d88c9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: notification-extension/ITBNotificationServiceExtension.swift

+22
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,37 @@
44

55
import UserNotifications
66

7+
public protocol ITBNotificationServiceExtensionDelegate {
8+
func notificationServiceDidReceive(_ request: UNNotificationRequest, bestAttemptContent: UNMutableNotificationContent, contentHandler: @escaping (UNNotificationContent) -> Void)
9+
}
10+
711
@objc open class ITBNotificationServiceExtension: UNNotificationServiceExtension {
812
var contentHandler: ((UNNotificationContent) -> Void)?
913
var bestAttemptContent: UNMutableNotificationContent?
14+
public static var itblNotificationDelegate: ITBNotificationServiceExtensionDelegate?
1015

1116
@objc override open func didReceive(_ request: UNNotificationRequest,
1217
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
1318
self.contentHandler = contentHandler
1419
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
1520

21+
if let itblNotificationDelegate = ITBNotificationServiceExtension.itblNotificationDelegate,
22+
let bestAttemptContent = bestAttemptContent {
23+
24+
let result = request.content.userInfo.contains {
25+
guard let itbl = $0.key as? String else {
26+
print("Iterable SDK notification service extension: failed to cast JSON key to string")
27+
return false
28+
}
29+
return itbl == JsonKey.Payload.metadata
30+
}
31+
32+
if !result {
33+
itblNotificationDelegate.notificationServiceDidReceive(request, bestAttemptContent: bestAttemptContent, contentHandler: contentHandler)
34+
return
35+
}
36+
}
37+
1638
resolveCategory(from: request.content)
1739

1840
retrieveAttachment(from: request.content)

0 commit comments

Comments
 (0)