> For the complete documentation index, see [llms.txt](https://rehanabbas.gitbook.io/adpluginx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rehanabbas.gitbook.io/adpluginx/installation/add-onesignal-to-project.md).

# Add Onesignal to Project

Open Your Flutter Ios Folder in Xcode.

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

<figure><img src="/files/Y4NjAMMxpvsTvEiQUshP" 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="/files/Nb6VD5ZHkxKoRnvVlubI" alt=""><figcaption></figcaption></figure>
```

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

```
<figure><img src="/files/QEMiO8TpceEWtCqA2pYm" alt=""><figcaption></figcaption></figure>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rehanabbas.gitbook.io/adpluginx/installation/add-onesignal-to-project.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
