# Notification Service Extension

Create and configure a notification service extension to support rich media attachments like images, animated GIFs, and videos in push notifications.

To support rich media attachments (images, animated GIFs, video) in push notifications, you need to create a [notification service extension](https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications) (NSE).

## Create a Notification Service Extension Target

1. In Xcode, click **File** → **New** → **Target...**.
2. Select **Notification Service Extension**.
3. Click **Next** and configure your extension:
   - **Product Name**: Your extension name (e.g., `NotificationServiceExtension`)
   - **Bundle Identifier**: Typically your app's bundle ID with a suffix (e.g., `com.example.app.NotificationServiceExtension`)

![Notification Service Extension](https://www.airship.com/docs/images/create-notification-service-extension_hu_8bb42b1a35cc5e03.webp)

4. Verify that your app target's **Embed App Extensions** includes the newly created extension.

![Notification Service Extension](https://www.airship.com/docs/images/embed-extension-in-app_hu_393854a222d22be6.webp)

## Install Dependencies


#### SPM



1. Select your service extension target in the Project Navigator.
2. Go to the **Package Dependencies** tab.
3. If you haven't already added the Airship package, click **+** and add: `https://github.com/urbanairship/ios-library`
4. Select the `AirshipNotificationServiceExtension` package product for your service extension target.

> **Note:** The `AirshipNotificationServiceExtension` package should only be added to the Notification Service Extension target, not the main app target.


5. Import the module:

```swift
import AirshipNotificationServiceExtension
```




#### CocoaPods



Add to your `Podfile`:

```ruby
target "<Your Service Extension Target Name>" do
  pod 'AirshipServiceExtension'
end
```


Install:

`$ pod install`



#### Carthage



1. Add `AirshipNotificationServiceExtension.framework` to your service extension target following [Carthage's instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).
2. Add to your `Cartfile`:

```text
github "urbanairship/ios-library"
```


3. Build:

`$ carthage update`

4. Verify that **Enable Modules** and **Link Frameworks Automatically** are enabled in Build Settings.



#### xcframeworks



1. Download the latest [iOS SDK release](https://github.com/urbanairship/ios-library/releases).
2. Add `AirshipNotificationServiceExtension.xcframework` to your **main app target**:
   - Select your main app target
   - Go to **General** → **Frameworks, Libraries, and Embedded Content**
   - Drag in `AirshipNotificationServiceExtension.xcframework`
   - Set **Embed** to **Embed & Sign**
3. Add `AirshipNotificationServiceExtension.xcframework` to your **service extension target**:
   - Select your service extension target
   - Go to **General** → **Frameworks, Libraries, and Embedded Content**
   - Add `AirshipNotificationServiceExtension.xcframework`
   - Set **Embed** to **Do Not Embed**
4. Configure the service extension's runpath:
   - Select your service extension target
   - Go to **Build Settings** → search for **Runpath Search Paths** (`LD_RUNPATH_SEARCH_PATHS`)
   - Add: `@executable_path/../../Frameworks`
5. Verify Build Settings for both targets:
   - **Enable Modules**: `Yes`
   - **Link Frameworks Automatically**: `Yes`

> **Note:** The framework must be embedded in the main app target, not the extension. Extensions cannot contain nested frameworks, which will cause App Store rejection. The runpath setting allows the extension to find the framework in the main app's `Frameworks` directory.





## Implement the Service Extension

Replace the default `NotificationService` implementation with Airship's base class:


#### Swift (SPM/Carthage/xcframeworks)


```swift
import AirshipNotificationServiceExtension

class NotificationService: UANotificationServiceExtension {

}
```



#### Swift (CocoaPods)


```swift
import AirshipServiceExtension

class NotificationService: UANotificationServiceExtension {

}
```



#### Objective-C (SPM/Carthage/xcframeworks)


```objc
// NotificationService.h
@import AirshipNotificationServiceExtension;

@interface NotificationService : UANotificationServiceExtension

@end

// NotificationService.m
@import Foundation;
#import "NotificationService.h"

@implementation NotificationService

@end
```



#### Objective-C (CocoaPods)


```objc
// NotificationService.h
@import AirshipServiceExtension;

@interface NotificationService : UANotificationServiceExtension

@end

// NotificationService.m
@import Foundation;
#import "NotificationService.h"

@implementation NotificationService

@end
```




That's it! The Airship base class handles downloading and attaching media from URLs in your push notifications. When you send a push notification with a media URL, the service extension will automatically download and attach the media before the notification is displayed.

## Related Documentation

- [Getting Started with Push Notifications](https://www.airship.com/docs/developer/sdk-integration/apple/push-notifications/getting-started/)
- [Installing the Airship SDK](https://www.airship.com/docs/developer/sdk-integration/apple/installation/getting-started/)

If you experience problems, see [Troubleshooting Notification Service Extensions](https://www.airship.com/docs/developer/sdk-integration/apple/troubleshooting/notification-service-extensions/) to verify setup and debug issues.
