# Add Onesignal to Project

Open Your Flutter Ios Folder in Xcode.

* Create New Target.
* Select Notification Extension and Name It OneSignalNotificationServiceExtension

<figure><img src="https://28070945-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCvyEr0F82Za2SV8l7N7A%2Fuploads%2FAEd5pQwB6fzJL7UppAVg%2Fimage.png?alt=media&#x26;token=b4f48fca-3aec-4562-882a-b5b993181d63" alt=""><figcaption></figcaption></figure>

*

```
<figure><img src="https://files.readme.io/c172285-Screen_Shot_2021-08-17_at_6.16.50_PM.png" alt=""><figcaption></figcaption></figure>
```

* Press `Cancel` on the `Activate Scheme` prompt

<figure><img src="https://files.readme.io/cdfe6de-2.png" alt=""><figcaption></figcaption></figure>

* In your project, in the `OneSignalNotificationServiceExtension/` folder, open `NotificationService.m` and replace the whole file contents with:

{% code title="NotificationService.Swift" lineNumbers="true" %}

```swift
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
        self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        
        if let bestAttemptContent = bestAttemptContent {   
            OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
        }
    }
    
    override func serviceExtensionTimeWillExpire() {
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            OneSignal.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
            contentHandler(bestAttemptContent)
        }
    } 
}
```

{% endcode %}

* In the main app target, select **Signing & Capabilities** > **All** > **+ Capability**, enable **Push Notifications**.
*

```
<figure><img src="https://28070945-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCvyEr0F82Za2SV8l7N7A%2Fuploads%2FEqTJDhh6Et3zXRTeDrgd%2Fimage.png?alt=media&#x26;token=49215b66-3131-40d0-b798-7256d35e8263" alt=""><figcaption></figcaption></figure>
```

* Next, enable **Background Modes** and check **Remote Notifications**.
*

```
<figure><img src="https://28070945-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCvyEr0F82Za2SV8l7N7A%2Fuploads%2FUCoosOGccJf5TCV03Rnb%2Fimage.png?alt=media&#x26;token=57a84c5f-9a3d-452b-9d66-f1df828b1d50" alt=""><figcaption></figcaption></figure>
```
