# Media Push

### Step 1: Create a New Notification Service Extension

To create a new Notification Service Extension to your application:

1. On **Xcode** click **File > New > Target**. Choose `Notification Service Extension`
2. Choose `Notification Service Extension`
3. A new class named `NotificationService` will be created. It should be extended from `NotificationServiceExtension` class.

Your `NotificationService` class should look like the following:

```swift
import UserNotifications
import NetmeraNotificationServiceExtension

class NotificationService: NotificationServiceExtension {
  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    super.didReceive(request, withContentHandler: contentHandler)
  }

  override func serviceExtensionTimeWillExpire() {
    super.serviceExtensionTimeWillExpire()
  }
}
```

### Optional: Integrating Notification Service Extension Using CocoaPods

If you're using a **Podfile** for dependency management, follow these steps along with the rest of the steps from 1 to 5:

* Add `NetmeraNotificationServiceExtension` in your Podfile:
* Install it to your extension target.

```ruby
pod 'NetmeraNotificationServiceExtension'
```

**Note:** If you're not using CocoaPods, you can skip this step.

### Step 2: Add App Group Capability

You need to add the App Groups capability to both your main app target and your Service Extension target via the Signing & Capabilities section.

1. Open your project in Xcode.
2. Go to the Signing & Capabilities tab.
3. Select App Groups from the list.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FkCs73FX1P5q9mIJvpibF%2Fimage.png?alt=media&#x26;token=c4359558-d1b6-42a9-9b91-52e5b964e5d6" alt="" width="563"><figcaption></figcaption></figure>

4. Add or select an existing App Group (e.g., `group.example.app`).
5. Repeat steps 2–6 for your **Service Extension target**.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FZzq4PnNPgyVnNyopiKUk%2FScreenshot%202025-05-13%20at%2011.32.39.png?alt=media&#x26;token=3bd05632-b682-4055-9a67-9087f185b4d7" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FKJD3eGzdiXlzKulNY9GI%2Fimage.png?alt=media&#x26;token=e5f7e4a8-9ceb-4e3a-a9d6-df4b9970dcb3" alt="" width="563"><figcaption></figcaption></figure>

6. Add the App Group name under the appropriate key (e.g., `NetmeraAppGroup`) to match the App Group you added in Xcode.
7. Open the `Netmera-Config.plist` file in your project.

### Step 3: Add Your `AppGroupName`

1. Add your `AppGroupName` in your Netmera-Config.plist.

```html
<key>sdk_params</key>
<dict>
    <key>app_group_name</key> // Add this line in Config.plist
    <string>{YourAppGroupName}</string> // Add this line in Config.plist
    <key>use_ui_scene</key>
    <false/>
    <key>api_key</key>
    <string>{API_KEY}</string>
    <key>custom_events</key>
    <array>
        <string>{YourCustomEvent}</string>
    </array>
</dict>
```

If you don't have a `Netmera-Config.plist` see the step here [#id-1.-configure-with-netmera-plist](https://user.netmera.com/netmera-developer-guide/platforms/ios/sdk-integration#id-1.-configure-with-netmera-plist "mention").

### Step 4: Select Targets in Target Membership

1. Select **all three targets** in the Target Membership section on the right.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FertVtobtWEuEhz9RRXbe%2FScreenshot%202024-09-05%20at%2016.33.36.png?alt=media&#x26;token=d85088b8-7ed7-4401-82b1-58c9dfa63804" alt="" width="563"><figcaption></figcaption></figure>

### Step 5: Select Main Project & Service Extension

1. Go to **Notification Service > Target Membership**.
2. Select both the main project and the service extension.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FclKNHzRR18FV6VGLo3xl%2FScreenshot%202024-09-05%20at%2016.32.52.png?alt=media&#x26;token=c54b11c7-2ac5-45bf-ad53-f5f3b7d05775" alt="" width="563"><figcaption></figcaption></figure>

### Step 6: Receiving Http Media Contents

#### Sample Service Extention Info.plist

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>NSExtension</key>
    <dict>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.usernotifications.service</string>
        <key>NSExtensionPrincipalClass</key>
        <string>$(PRODUCT_MODULE_NAME).NotificationService</string>
    </dict>
</dict>
</plist>
```

If you want to allow your application to receive http media contents:

1. Click `Info.plist` under **Notification Service Extension,**
2. Add **App Transport Security Settings,**
3. &#x20;Add **Allow Arbitrary Loads** under App Transport Security Settings and set it to **YES.**

### **Troubleshooting**

If push notifications do not display correctly:

1. Go to **Build Settings > Runpath Search Paths** in the extension target. Ensure the following paths are added:

```plaintext
@executable_path/../../Frameworks  
@executable_path/Frameworks  
@loader_path/Frameworks
```

2. Remove the **default label** in **MainInterface**.
