Created
June 28, 2020 20:05
-
-
Save saud978/1000af1595c2bb717a74a75c9caaa123 to your computer and use it in GitHub Desktop.
OneSignal Push Notifications Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UserNotifications | |
import OneSignal | |
class NotificationService: UNNotificationServiceExtension { | |
var contentHandler: ((UNNotificationContent) -> Void)? | |
var receivedRequest: UNNotificationRequest! | |
var bestAttemptContent: UNMutableNotificationContent? | |
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { | |
self.receivedRequest = request; | |
self.contentHandler = contentHandler | |
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) | |
if let bestAttemptContent = bestAttemptContent { | |
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.bestAttemptContent) | |
contentHandler(bestAttemptContent) | |
} | |
} | |
override func serviceExtensionTimeWillExpire() { | |
// Called just before the extension will be terminated by the system. | |
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. | |
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { | |
OneSignal.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent) | |
contentHandler(bestAttemptContent) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment