Comment on page
Add Onesignal to Project
Open Your Flutter Ios Folder in Xcode.
- Create New Target.
- Select Notification Extension and Name It OneSignalNotificationServiceExtension

-
- Press
Cancel
on theActivate Scheme
prompt

- In your project, in the
OneSignalNotificationServiceExtension/
folder, openNotificationService.m
and replace the whole file contents with:
NotificationService.Swift
1
import UserNotifications
2
3
import OneSignal
4
5
class NotificationService: UNNotificationServiceExtension {
6
7
var contentHandler: ((UNNotificationContent) -> Void)?
8
var receivedRequest: UNNotificationRequest!
9
var bestAttemptContent: UNMutableNotificationContent?
10
11
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
12
self.receivedRequest = request
13
self.contentHandler = contentHandler
14
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
15
16
if let bestAttemptContent = bestAttemptContent {
17
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
18
}
19
}
20
21
override func serviceExtensionTimeWillExpire() {
22
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
23
OneSignal.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
24
contentHandler(bestAttemptContent)
25
}
26
}
27
}
- In the main app target, select Signing & Capabilities > All > + Capability, enable Push Notifications.
-
- Next, enable Background Modes and check Remote Notifications.
-