iOS Notification Service Extension

In order to take advantage of iOS 10 notification attachments, such as images, animated gifs, and video, you will need to create a notification service extension.

Create a new iOS target in Xcode

In Xcode, click the File menu, select New » Target..., then click the Notification Service Extension template.


Typically extensions are named with a suffix on the main application's ID. In this example the bundle identifier would be com.urbanairship.sample.ExampleServiceExtension.

Check that your app's target Embed App Extensions contains your newly created extension.

Then in your project's Build Settings you must set the iOS Deployment Target to iOS 10+.

Install AirshipAppExtensions

CocoaPods

Specify the UrbanAirship-iOS-AppExtensions in your podfile and your newly created service extension as the target. Make sure to run pod install after modifying the podfile.

Example podfile:

target "SampleExtension" do pod 'UrbanAirship-iOS-AppExtensions' end

Install using the following command:

$ pod install

Carthage

Before you begin, ensure you have Carthage installed.

Adding the SDK framework to your application

Follow Carthage's adding frameworks to an application instructions to add AirshipAppExtensions.framework to your application.

If you are also using the Urban Airship SDK, follow the instructions in the iOS SDK Guide.

Specify the Urban Airship iOS SDK in your cartfile:

github "urbanairship/ios-library"

Verify Enable Modules and Link Frameworks Automatically are enabled in the project's Build Settings.

Manual

Drag the AirshipAppExtensions.framework into your app project from iOS SDK.


Add AirshipAppExtensions to Target Dependencies in your project's Build Phases.


Add AirshipAppExtensions.framework to a Copy Files phase in your project's Build Phases. Ensure "Frameworks" is set as the destination.


Link against AirshipAppExtensions.framework in your extension's Build Phases.

Modify the Extension

Extension:

// Notification.swift

import AirshipAppExtensions

class NotificationService: UAMediaAttachmentExtension {

}
// NotificationService.h

@import AirshipAppExtensions;

@interface NotificationService : UAMediaAttachmentExtension

@end

// NotificationService.m

@import Foundation;
#import "NotificationService.h"

@implementation NotificationService

@end

Delete all dummy source code for your new extension and inherit from UAMediaAttachmentExtension in NotificationService.