iOS SDK Setup
Integrate Push Notifications into your native iOS app (UIKit, SwiftUI, or Objective-C) to receive and handle push notifications via APNs.
v1.0.6-beta. Not for production use. APIs may change without notice. Pin the exact version.
- Make sure to configure the App ID properly. For additional information see Getting started
- Configure your push credentials in the AppsOnAir console under App Settings → Push Notifications — upload your APNs Auth Key (.p8) before sending any notifications.
Requirements
| Minimum | |
|---|---|
| iOS | 15.0 |
| Xcode | 16+ |
| Swift | 6.2 (SPM) · 5.9 (CocoaPods) |
| Objective-C | Fully supported via AOAPush* facade classes |
A real device is required to receive APNs tokens. The SDK emits a mock token on Simulator so your registration flow is still testable.
Basic push — Steps 1–5 only. No extension targets needed:
- Text notifications with title and body
- Tap-to-open and deep links
- Foreground display control
- User targeting, tags, segments, opt-in / opt-out
Advanced push — requires optional extension targets. Skip these if you only need basic push:
| Feature | Additional setup |
|---|---|
| Images in notifications | Notification Service Extension (NSE) |
| Badge auto-increment | NSE + App Group |
| Delivered analytics | NSE + App Group |
| Custom long-press view | NSE + Notification Content Extension (NCE) |
| Silent push (background data, no alert) | Background Modes → Remote notifications (Step 1). No extension needed. See Silent Push |
Step 1: Apple Capabilities
Push notifications on iOS require two capabilities on the main app target. Without them, the device will not register with APNs and no tokens will be generated.
In Xcode, select your app target → Signing & Capabilities:
- Add Push Notifications — required for APNs registration and push delivery.
- Add Background Modes → enable Remote notifications — required for silent pushes and background delivery.
| Target | Capabilities |
|---|---|
| Main app | Push Notifications, Background Modes → Remote notifications, App Groups (if you use the NSE) |
| Notification Service Extension (NSE) | App Groups (same group as the main app) |
| Notification Content Extension (NCE) | None |
See Notification Service Extension and Notification Content Extension.
iOS always shows your app icon on notifications. APNs has no field for a custom notification icon, so there's nothing to configure (the same applies to OneSignal). To change it, update the app icon in Assets.xcassets and ship a new build.
Step 2: Add the SDK
The SDK is distributed as three separate products so you only link what each target needs.
- Swift Package Manager
- CocoaPods
- In Xcode: File > Add Package Dependencies...
- Paste the repository URL and resolve.
- Link the correct products to each target:
| Product | Link to |
|---|---|
AppsOnAir-AppPush | Main app target |
AppsOnAir-AppPush-ServiceExt | Notification Service Extension target only |
AppsOnAir-AppPush-ContentExt | Notification Content Extension target only |
platform :ios, '15.0'
target 'MyApp' do
use_frameworks!
pod 'AppsOnAir-AppPush', '>= 1.0.6-beta', '< 1.1'
end
# Optional — only if you add the extensions (see Notification Service / Content Extension below)
target 'NotificationService' do
pod 'AppsOnAir-AppPush-ServiceExt', '>= 1.0.6-beta', '< 1.1'
end
target 'NotificationContent' do
pod 'AppsOnAir-AppPush-ContentExt', '>= 1.0.6-beta', '< 1.1'
end
Use the standalone AppsOnAir-AppPush-ServiceExt and AppsOnAir-AppPush-ContentExt pods for extension targets. Their modules (AppsOnAir_AppPush_ServiceExt / AppsOnAir_AppPush_ContentExt) match the SPM products, so extension code is the same with either package manager.
The older AppsOnAir-AppPush/ServiceExtension and AppsOnAir-AppPush/ContentExtension subspecs are deprecated. With use_frameworks! they fail at archive time with "Multiple commands produce AppsOnAir_AppPush.framework". To migrate, switch the pod and change import AppsOnAir_AppPush to import AppsOnAir_AppPush_ServiceExt (NSE) or import AppsOnAir_AppPush_ContentExt (NCE).
Run:
pod repo update
pod install
Then open <project>.xcworkspace.
Step 3: Configure Info.plist
The AppsonairAppId key is already covered in Getting Started — ensure it is present in your Info.plist before continuing.
If you use the Notification Service Extension, the main app and NSE must share an App Group. See NSE Step 3 for the App Group and AppsOnAirAppGroup key.
Step 4: Initialize the SDK
Call initialize() inside application(_:didFinishLaunchingWithOptions:) so the SDK registers with APNs before any scene connects.
- Swift (UIKit)
- SwiftUI
- Objective-C
import UIKit
import AppsOnAir_AppPush
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Optional: verbose logging before initialize (dev builds only)
AppPushService.Debug.logLevel = .verbose
// Register background sync handlers. Must be called before any scene connects.
AppsOnAirBackgroundSync.registerHandlers()
AppPushService.initialize(debug: true)
AppPushService.setListener(self)
AppPushService.Notifications.requestPermission()
AppsOnAirBackgroundSync.scheduleIfNeeded()
return true
}
}
// MARK: - PushListener
extension AppDelegate: PushListener {
func onAPNsTokenUpdated(token: String, environment: APNsEnvironment) {
// APNs token registered or refreshed — SDK handles registration automatically
}
func onNotificationReceived(notification: PushNotification) {
// Notification received while app is in foreground
}
func onNotificationOpened(notification: PushNotification) {
// User tapped the notification
}
func onError(_ error: PushError) {
// Handle SDK error
}
}
import SwiftUI
import AppsOnAir_AppPush
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate, PushListener {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
AppPushService.Debug.logLevel = .verbose
AppsOnAirBackgroundSync.registerHandlers()
AppPushService.initialize(debug: true)
AppPushService.setListener(self)
AppPushService.Notifications.requestPermission()
AppsOnAirBackgroundSync.scheduleIfNeeded()
return true
}
func onAPNsTokenUpdated(token: String, environment: APNsEnvironment) { }
func onNotificationReceived(notification: PushNotification) { }
func onNotificationOpened(notification: PushNotification) { }
func onError(_ error: PushError) { }
}
// AppDelegate.h
#import <UIKit/UIKit.h>
@import AppsOnAir_AppPush;
@interface AppDelegate : UIResponder <UIApplicationDelegate, AOAPushListener>
@property (strong, nonatomic) UIWindow *window;
@end
// AppDelegate.m
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AOAPushDebug setLogLevel:AOALogLevelVerbose];
[AOAPushBackgroundSync registerHandlers];
[AOAPush initializeWithDebug:YES swizzle:YES];
[AOAPush setListener:self];
[AOAPushNotifications requestPermission];
[AOAPushBackgroundSync scheduleIfNeeded];
return YES;
}
// AOAPushListener — all methods are optional
- (void)onAPNsTokenUpdatedWithToken:(NSString *)token
environment:(AOAAPNsEnvironment)environment { }
- (void)onNotificationReceivedWithNotification:(AOAPushNotification *)notification { }
- (void)onNotificationOpenedWithNotification:(AOAPushNotification *)notification { }
- (void)onError:(NSError *)error { }
The SDK hooks the APNs token and notification delegate methods automatically. This also works when another library owns UNUserNotificationCenter.current().delegate (for example Notifee, a Flutter plugin, or your own delegate): AppsOnAir pushes still reach the SDK and the other delegate keeps receiving its own notifications.
Step 5: Background Sync (Info.plist)
Background sync lets the SDK silently fetch updates while your app is not in the foreground. Add the task identifier to Info.plist so iOS grants permission to run background tasks.
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.appsonair.push.background-sync</string>
</array>
Feature Guides
Observers
React to subscription state changes and login/logout events without polling.
- Swift
- Objective-C
// Observe opt-in / token changes
AppPushService.User.pushSubscription.addObserver(self)
func onPushSubscriptionDidChange(state: PushSubscriptionChangedState) {
print("optedIn:", state.current.optedIn)
}
// Observe login / logout
AppPushService.User.addObserver(self)
func onUserStateDidChange(state: UserChangedState) {
print(state.current.externalId ?? "anonymous")
}
[AOAPushUser addPushSubscriptionObserver:self];
- (void)onPushSubscriptionDidChangeWithState:(AOAPushSubscriptionChangedState *)state {
NSLog(@"optedIn: %d", state.current.optedIn);
}
[AOAPushUser addUserStateObserver:self];
- (void)onUserStateDidChangeWithState:(AOAUserChangedState *)state {
NSLog(@"%@", state.current.externalId ?: @"anonymous");
}
Permission
Request and observe the notification permission.
- Swift
- Objective-C
// Check current status (synchronous)
let granted = AppPushService.Notifications.permission
let canRequest = AppPushService.Notifications.canRequestPermission
if !granted && canRequest {
AppPushService.Notifications.requestPermission()
}
// Permanently denied → open Settings:
AppPushService.Notifications.requestPermission(fallbackToSettings: true)
// Observe permission changes
AppPushService.Notifications.addPermissionObserver(self)
func onNotificationPermissionDidChange(permission: Bool) {
print("permission granted:", permission)
}
BOOL granted = [AOAPushNotifications permission];
BOOL canRequest = [AOAPushNotifications canRequestPermission];
[AOAPushNotifications requestPermission];
[AOAPushNotifications addPermissionObserver:self];
- (void)onNotificationPermissionDidChangeWithPermission:(BOOL)permission { }
User Identity
Associate a known user ID with the device after login so you can target push notifications to specific users from the portal.
- Swift
- Objective-C
AppPushService.login("user_12345") // call when your user signs in
AppPushService.logout() // call on sign-out — clears tags and aliases
[AOAPush login:@"user_12345"];
[AOAPush logout];
Tags & Segmentation
Tags are key-value pairs you attach to a device to enable audience segmentation.
- Swift
- Objective-C
AppPushService.User.addTag(key: "plan", value: "premium")
AppPushService.User.addTags(["plan": "premium", "region": "us-east"])
AppPushService.User.removeTag("plan")
AppPushService.User.removeTags(["plan", "region"])
// Read from local cache (synchronous)
let cached = AppPushService.User.getTags()
// Fetch fresh copy from backend (async)
AppPushService.User.getTags { tags in
print(tags)
}
[AOAPushUser addTagWithKey:@"plan" value:@"premium"];
[AOAPushUser addTags:@{@"plan": @"premium", @"region": @"us"}];
[AOAPushUser removeTag:@"plan"];
[AOAPushUser removeTags:@[@"plan", @"region"]];
// Local cache
NSDictionary *tags = [AOAPushUser getTags];
// Backend fetch
[AOAPushUser fetchTagsFromBackendWithCompletion:^(NSDictionary *tags) {
NSLog(@"%@", tags);
}];
Language
Override the device locale for this user. Uses ISO 639-1 codes ("en", "fr", "de").
- Swift
- Objective-C
AppPushService.User.setLanguage("fr")
let lang = AppPushService.User.language
[AOAPushUser setLanguage:@"fr"];
NSString *lang = [AOAPushUser language];
Aliases & Email
Map this device to an ID in an external system (CRM, helpdesk, analytics) and associate an email address. Each subscription keeps one email, so calling addEmail again replaces the previous address.
- Swift
- Objective-C
AppPushService.User.addAlias(label: "crm_id", id: "CRM-9876")
AppPushService.User.addAliases(["crm_id": "CRM-9876", "hubspot_id": "HS-42"])
AppPushService.User.removeAlias("crm_id")
AppPushService.User.addEmail("[email protected]")
AppPushService.User.removeEmail("[email protected]")
[AOAPushUser addAliasWithLabel:@"crm_id" id:@"CRM-9876"];
[AOAPushUser addAliases:@{@"crm_id": @"CRM-9876"}];
[AOAPushUser removeAlias:@"crm_id"];
[AOAPushUser addEmail:@"[email protected]"];
[AOAPushUser removeEmail:@"[email protected]"];
Opt-in / Opt-out
Let users stop receiving push notifications without revoking the OS-level APNs permission.
- Swift
- Objective-C
// Stop delivery (preserves APNs token)
AppPushService.User.pushSubscription.optOut()
// Resume delivery
AppPushService.User.pushSubscription.optIn()
// Read state
let isOptedIn = AppPushService.User.pushSubscription.optedIn
[AOAPushUser optOut];
[AOAPushUser optIn];
BOOL optedIn = [AOAPushUser pushSubscriptionOptedIn];
Foreground Display
By default the SDK shows banners even when the app is in the foreground. Add a lifecycle listener to intercept and suppress any notification.
- Swift
- Objective-C
AppPushService.Notifications.addForegroundLifecycleListener(self)
func onWillDisplay(event: NotificationWillDisplayEvent) {
// Call preventDefault() to suppress the banner; omit to show it normally
event.preventDefault()
}
[AOAPushNotifications addForegroundLifecycleListener:self];
- (void)onWillDisplayWithEvent:(AOANotificationWillDisplayEvent *)event {
[event preventDefault];
}
Click / Open Listener
Fired when the user taps a notification or one of its action buttons.
- Swift
- Objective-C
AppPushService.Notifications.addClickListener(self)
func onClick(event: NotificationClickEvent) {
print(event.result.actionId ?? "body tap")
print(event.result.url ?? "")
}
[AOAPushNotifications addClickListener:self];
- (void)onClickWithEvent:(AOANotificationClickEvent *)event {
NSLog(@"action: %@ url: %@",
event.result.actionId ?: @"body tap",
event.result.url ?: @"");
}
Badge Count (Optional)
Manually control the notification badge count on the app icon.
- Swift
- Objective-C
AppPushService.setBadgeCount(5)
AppPushService.incrementBadgeCount(by: 1)
AppPushService.clearBadgeCount()
// Auto-clear when app comes to foreground (default = true)
AppPushService.autoClearBadgeOnForeground = false // switch to count-down mode
[AOAPush setBadgeCount:5];
[AOAPush incrementBadgeCountBy:1];
[AOAPush clearBadgeCount];
[AOAPush setAutoClearBadgeOnForeground:NO];
Silent Push (Optional)
A silent push delivers data to your app without showing a notification. iOS wakes the app in the background so it can run lightweight work, such as a content sync. The push still counts as delivered in analytics.
Requirements:
- Background Modes → Remote notifications enabled (Step 1).
- The payload has
aps.content-available: 1and noalert,sound, orbadge. - Notification permission is not needed. Silent pushes reach devices that declined it.
Set the handler before initialize(), and call completion when your work finishes. iOS gives you about 30 seconds.
- Swift
- Objective-C
AppPushService.onSilentPushReceived = { userInfo, completion in
// run lightweight background work (≤ 30 s)
let syncType = userInfo["sync_type"] as? String
completion(.newData) // or .noData / .failed
}
AOAPush.onSilentPushReceived = ^(NSDictionary *userInfo,
void (^completion)(UIBackgroundFetchResult)) {
// run lightweight background work (≤ 30 s)
completion(UIBackgroundFetchResultNewData);
};
The SDK hooks application(_:didReceiveRemoteNotification:fetchCompletionHandler:) for you. If your AppDelegate already implements that method, the SDK calls yours instead, so forward the push to the SDK from it:
- Swift
- Objective-C
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
AppPushService.handleSilentPush(userInfo, fetchCompletionHandler: completionHandler)
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
[AOAPush handleSilentPush:userInfo fetchCompletionHandler:handler];
}
{
"aps": { "content-available": 1 },
"notification_id": "notif-sync-001",
"sync_type": "orders"
}
To send a silent push from your backend, see REST API → Silent Notifications.
iOS throttles silent pushes. Low Power Mode, a disabled Background App Refresh, or an app swiped away from the App Switcher stop delivery entirely. See When Notifications Won't Be Delivered.
Remove Notifications (Optional)
Remove delivered notifications from the notification centre.
- Swift
- Objective-C
AppPushService.Notifications.clearAllNotifications()
AppPushService.Notifications.removeNotification(withIdentifier: "abc")
AppPushService.Notifications.removeNotifications(withIdentifiers: ["a", "b"])
[AOAPushNotifications clearAllNotifications];
[AOAPushNotifications removeNotificationWithIdentifier:@"abc"];
[AOAPushNotifications removeNotificationsWithIdentifiers:@[@"a", @"b"]];
Notification Service Extension (Optional — Rich Push)
Steps 1–5 are all you need for basic push notifications — text, tap-to-open, and deep links. The NSE and NCE are optional extensions you add only when you need:
| Feature | Requires |
|---|---|
| Images in notifications | NSE |
| Badge auto-increment | NSE + App Group |
| Delivered analytics | NSE + App Group |
| Custom expanded view (long-press) | NSE + NCE |
The Notification Service Extension (NSE) runs in its own process before iOS displays a notification. With the AppsOnAir NSE in place, the SDK:
- downloads and attaches an image, video or audio file (up to 3 attachments; the first one appears in the banner)
- applies the
title,subtitle,bodyandsoundoverrides from the payload - updates the app-icon badge (
badge,badge_increment) - registers action buttons from the payload's
actionsarray - records the Delivered analytics event
Without an NSE, iOS still shows the notification, but you get no images, no badge increments and no delivery tracking.
Step 1: Add the NSE target
- In Xcode: File → New → Target → Notification Service Extension. Name it, for example,
NotificationService. - When Xcode asks to activate the scheme, choose Cancel so you keep debugging the main app.
- Select the new target → General → set Minimum Deployments to the same version as your app (15.0 or higher).
Xcode sets a new extension to the latest iOS. On devices running an older iOS, the extension silently never runs — no crash and no log.
Step 2: Link the SDK to the NSE
- Swift Package Manager
- CocoaPods
In the package's Add to Target list, choose your NSE target for AppsOnAir-AppPush-ServiceExt. Link it to the NSE only, never to the main app.
Module to import: AppsOnAir_AppPush_ServiceExt
target 'NotificationService' do
pod 'AppsOnAir-AppPush-ServiceExt', '>= 1.0.6-beta', '< 1.1'
end
Module to import: AppsOnAir_AppPush_ServiceExt
Don't use the deprecated AppsOnAir-AppPush/ServiceExtension subspec (see the note in Step 2).
Step 3: Share an App Group
The App Group is how the NSE gets the App ID and subscription from the main app (for delivery receipts) and how it keeps the running badge count.
-
Add the App Groups capability to the main app and the NSE target, with the same identifier:
group.<your-main-app-bundle-id>.appsonair -
If you use exactly that name, the SDK finds it automatically. If you use any other name, add it to both
Info.plistfiles:Info.plist (main app AND NSE)<key>AppsOnAirAppGroup</key>
<string>group.com.yourcompany.app.appsonair</string> -
In the Apple Developer Portal → Identifiers, enable the App Group on both App IDs (main app and NSE), then regenerate the provisioning profiles.
Xcode writes the group to each target's .entitlements file automatically:
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.yourcompany.app.appsonair</string>
</array>
The automatic lookup inside the NSE removes the last part of the NSE bundle ID (com.acme.app.NotificationService → com.acme.app). Keep the NSE bundle ID as <main-app-bundle-id>.<Name> (the Xcode default), or set AppsOnAirAppGroup explicitly.
Step 4: Replace NotificationService
- Swift (subclass)
- Swift (existing NSE class)
- Objective-C
import AppsOnAir_AppPush_ServiceExt
class NotificationService: AppsOnAirNotificationServiceExtension {
// Nothing else required.
}
Optionally, change the content before the SDK applies its overrides and attachments:
import UserNotifications
class NotificationService: AppsOnAirNotificationServiceExtension {
override func modifyContent(_ content: UNMutableNotificationContent,
request: UNNotificationRequest) {
content.threadIdentifier = "orders"
}
}
Use this if you already have a UNNotificationServiceExtension subclass or chain another SDK.
import UserNotifications
import AppsOnAir_AppPush_ServiceExt
class NotificationService: UNNotificationServiceExtension {
private var contentHandler: ((UNNotificationContent) -> Void)?
private var bestAttemptContent: UNMutableNotificationContent?
private var receivedRequest: UNNotificationRequest?
override func didReceive(_ request: UNNotificationRequest,
withContentHandler handler: @escaping (UNNotificationContent) -> Void) {
guard let content = request.content.mutableCopy() as? UNMutableNotificationContent
else { return handler(request.content) }
receivedRequest = request
bestAttemptContent = content
contentHandler = handler
// Blocks until done, then calls `handler` exactly once.
AppPushServiceExtension.didReceiveNotificationExtensionRequest(
request, with: content, withContentHandler: handler)
contentHandler = nil
}
override func serviceExtensionTimeWillExpire() {
guard let request = receivedRequest, let handler = contentHandler else { return }
handler(AppPushServiceExtension.serviceExtensionTimeWillExpireRequest(
request, with: bestAttemptContent) ?? request.content)
contentHandler = nil
}
}
Objective-C cannot subclass the Swift base class. Use the static AOAPushExtension methods.
#import "NotificationService.h"
@import AppsOnAir_AppPush_ServiceExt;
@interface NotificationService ()
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, copy) void (^contentHandler)(UNNotificationContent *);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request
withContentHandler:(void (^)(UNNotificationContent *))contentHandler {
self.receivedRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
[AOAPushExtension didReceiveNotificationRequest:request
withContentHandler:contentHandler];
self.contentHandler = nil;
}
- (void)serviceExtensionTimeWillExpire {
[AOAPushExtension serviceExtensionTimeWillExpireRequest:self.receivedRequest
bestAttemptContent:self.bestAttemptContent
contentHandler:self.contentHandler];
self.contentHandler = nil;
}
@end
Keep the Xcode-generated NSE Info.plist entries:
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
Step 5: Send mutable-content
iOS runs the NSE only when the APNs payload contains "mutable-content": 1. With the Send Push API, set "mutable_content": true.
{
"aps": {
"alert": { "title": "New offer", "body": "Tap to view" },
"mutable-content": 1
},
"notification_id": "notif-abc-123",
"big_picture": "https://cdn.example.com/offer.jpg"
}
Attachment rules
| Source keys | attachments (array of URLs or {id, url}, max 3) → otherwise big_picture → image_url → large_icon → video_url |
| Protocol | HTTPS only |
| Types | jpg, jpeg, png, gif, heic, webp, mp4, m4v, mov, mp3, m4a, wav, aiff |
| Limits | 15 s per download, 25 s in total. Apple's size limits apply (image 10 MB, audio 5 MB, video 50 MB) |
| Failure | The attachment is dropped and the notification is still shown |
Notification Content Extension (Optional — Custom Long-Press View)
The Notification Content Extension (NCE) replaces the expanded (long-press) view of a notification. The SDK's built-in AppsOnAirContentViewController shows:
- a full-width image (200 pt high) from the first attachment, which the NSE downloads
- the title (up to 2 lines)
- the full body
- It shows images only. A video or audio attachment isn't played; the image area is hidden instead.
- It doesn't download media itself. Set up the NSE as well if you want the image.
- It doesn't need an App Group.
Step 1: Add the NCE target
- File → New → Target → Notification Content Extension. Name it, for example,
NotificationContent. - Set Minimum Deployments to match your app (15.0 or higher).
Step 2: Link the SDK to the NCE
- Swift Package Manager
- CocoaPods
Add AppsOnAir-AppPush-ContentExt to the NCE target only.
Module to import: AppsOnAir_AppPush_ContentExt
target 'NotificationContent' do
pod 'AppsOnAir-AppPush-ContentExt', '>= 1.0.6-beta', '< 1.1'
end
Module to import: AppsOnAir_AppPush_ContentExt
Don't use the deprecated AppsOnAir-AppPush/ContentExtension subspec (see the note in Step 2).
Step 3: Replace the view controller
Delete MainInterface.storyboard (Move to Trash) — the SDK builds its UI in code. Then replace NotificationViewController.swift:
- Swift
- Objective-C
import UserNotifications
import AppsOnAir_AppPush_ContentExt
class NotificationViewController: AppsOnAirContentViewController {
// Optional: customise on top of the built-in image + title + body.
override func configure(with notification: UNNotification) {
super.configure(with: notification)
}
}
Objective-C subclasses AOAContentViewController, which has the same layout.
@import AppsOnAir_AppPush_ContentExt;
@interface NotificationViewController : AOAContentViewController
@end
#import "NotificationViewController.h"
@implementation NotificationViewController
// Optional:
- (void)configureWithNotification:(UNNotification *)notification {
[super configureWithNotification:notification];
}
@end
For Objective-C, set NSExtensionPrincipalClass to NotificationViewController (no module prefix).
If you'd rather design the UI yourself, keep the storyboard, implement UNNotificationContentExtension in your own UIViewController, and don't link the SDK to the NCE at all. The NSE still downloads the attachment for you.
Step 4: Configure the NCE Info.plist
Replace NSExtensionMainStoryboard with NSExtensionPrincipalClass, and set your category ID:
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<!-- Must equal aps.category in the payload -->
<key>UNNotificationExtensionCategory</key>
<string>aoa_rich</string>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationViewController</string>
</dict>
To handle several categories, make UNNotificationExtensionCategory an <array> of strings.
Step 5: Send the category
iOS opens the NCE only when aps.category matches UNNotificationExtensionCategory. With the Send Push API, set "ios_category".
{
"aps": {
"alert": { "title": "Order shipped", "body": "Long-press to see details" },
"category": "aoa_rich",
"mutable-content": 1
},
"notification_id": "notif-abc-123",
"big_picture": "https://cdn.example.com/parcel.jpg"
}
If a payload has actions but no aps.category, the NSE assigns a generated category (aoa.actions.<ids>) so the buttons appear. That generated category won't match your NCE. Always send aps.category when you want the NCE.
Push Payload Reference
Custom keys are siblings of aps, not inside it.
| Key | Type | Notes |
|---|---|---|
notification_id | String | Available in callbacks as notification.id. Used for delivery receipts |
title / subtitle / body | String | Override aps.alert. NSE only |
sound | String | "default" or a bundled .caf/.aiff file name. Overrides aps.sound. NSE only |
big_picture | String (https) | Main image. NSE only. Wins over image_url and large_icon |
image_url | String (https) | Legacy alias for big_picture. NSE only |
large_icon | String (https) | Used as the image only if the two keys above are absent. iOS has no separate thumbnail. NSE only |
video_url | String (https) | Used when no image key is set. NSE only |
attachments | [String] or [{id, url}] | Up to 3 media URLs. Takes precedence over all keys above. NSE only |
badge | Int | Absolute badge count. NSE only |
badge_increment | Int | Delta added to the running total. NSE and App Group |
actions | [{id, title, foreground?, destructive?}] | Action buttons, registered by the NSE |
aps.category | String | Routes the notification to your NCE |
aps.content-available | Int | 1 with no alert makes the push silent: the app is woken in the background and nothing is shown |
When Notifications Won't Be Delivered
Push delivery depends on OS settings and device state — not just your code. The following conditions can silently block or delay delivery regardless of correct SDK integration.
| Condition | Affects | Effect |
|---|---|---|
| Low Power Mode | Silent only | iOS suspends Background App Refresh and silent push delivery entirely while Low Power Mode is active. Delivery resumes when Low Power Mode is turned off or the device is charging. Visible notifications are unaffected. |
| Background App Refresh disabled | Silent only | If the user has turned off Background App Refresh for the app (Settings → General → Background App Refresh → [Your App]), iOS will not wake the app for silent pushes. |
| Kill mode (app swiped off App Switcher) | Silent only | If the user swipes the app off the App Switcher, iOS will not deliver silent pushes until the user manually relaunches the app. This is an iOS OS policy and cannot be worked around in code. Visible notifications are still delivered and tappable. |
| Apple rate limiting | Silent only | Apple allows only a limited number of silent pushes per hour per device. If too many are sent in a short window, excess pushes are deferred or dropped silently. |
| Low battery | Silent only | As battery level drops (roughly below 20%), iOS becomes more aggressive at deferring background work even without Low Power Mode enabled. |
| No network / poor signal | Silent only | APNs holds the push until the device reconnects, up to the apns-expiration window in the request. |
| APNs on Simulator | Silent & visible | APNs device tokens are not issued on the iOS Simulator. Always test push on a real device. |
| Permission denied | Visible only | Silent pushes don't require permission. Visible notifications are blocked if the user permanently denies permission. |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| No APNs token on device | Push Notifications capability missing | Add via Signing & Capabilities |
| NSE not invoked | mutable-content: 1 absent from payload | Add it (mutable_content: true in the Send Push API) |
| NSE not invoked | NSE deployment target is higher than the device's iOS version | Set the NSE's Minimum Deployments to your app's (15.0+) |
| Image not shown | URL isn't HTTPS, file type isn't supported, or the download took longer than 15 s | Use HTTPS and a supported type. Check the device console for [AppPushService NSE] logs |
| No Delivered analytics | App Group missing or different between app and NSE | Use the same group on both targets, and add AppsOnAirAppGroup to both Info.plist files if you don't use the default name |
App Group not resolvable in NSE logs | NSE can't find the group | Add AppsOnAirAppGroup to the NSE Info.plist |
CFPrefsPlistSource warning | Provisioning profile doesn't include the App Group | Enable the group on both App IDs in the Developer Portal and regenerate the profiles |
| Badge increments ignored | No App Group, so there's nowhere to store the running total | Configure the App Group, or send an absolute badge |
| NCE not shown on long-press | aps.category missing or different from UNNotificationExtensionCategory | Send the exact same category string |
| NCE shows a blank view / crashes | NSExtensionMainStoryboard still set, or NSExtensionPrincipalClass has no module prefix | Use $(PRODUCT_MODULE_NAME).NotificationViewController and delete the storyboard key |
| NCE shows text but no image | NSE not set up, or the attachment is a video | Set up the NSE. The built-in NCE renders images only |
| Archive fails: "Multiple commands produce AppsOnAir_AppPush.framework" | Extension uses the deprecated AppsOnAir-AppPush/ServiceExtension or /ContentExtension subspec | Switch to the AppsOnAir-AppPush-ServiceExt / AppsOnAir-AppPush-ContentExt pods and update the import |
pod install: "Unable to find a specification for AppsOnAir-AppPush-ServiceExt" | Local spec index is out of date | Run pod install --repo-update |
| "Extension version must match parent app" warning | Build number differs between targets | Use the same CURRENT_PROJECT_VERSION on the app, NSE and NCE |
| Silent push handler never fires | Background Modes → Remote notifications missing, Low Power Mode on, or app swiped away | Enable the capability. See When Notifications Won't Be Delivered |
Silent push handler never fires (custom AppDelegate) | Your didReceiveRemoteNotification:fetchCompletionHandler: doesn't forward to the SDK | Call AppPushService.handleSilentPush(_:fetchCompletionHandler:) from it |
| Background sync never fires | registerHandlers() called too late | Call it before any scene connects in application(_:didFinishLaunchingWithOptions:) |
ObjC objc_subclassing_restricted | Subclassing a Swift base class from ObjC | NSE: use AOAPushExtension. NCE: subclass AOAContentViewController |
Setup Checklist
Main app
-
AppsonairAppIdis inInfo.plist - Push Notifications and Background Modes → Remote notifications are enabled
-
AppsOnAir-AppPushis linked, andinitialize()is called indidFinishLaunchingWithOptions -
BGTaskSchedulerPermittedIdentifierscontainscom.appsonair.push.background-sync
NSE (images, badge, delivery analytics)
- NSE target created, with Minimum Deployments matching the app
-
AppsOnAir-AppPush-ServiceExtis linked to the NSE only -
NotificationServicesubclassesAppsOnAirNotificationServiceExtension - The same App Group is on the app and the NSE, and enabled on both App IDs in the Developer Portal
-
AppsOnAirAppGroupis in bothInfo.plistfiles (unless you usegroup.<bundle-id>.appsonair) - Pushes are sent with
mutable-content: 1
NCE (custom expanded view)
- NCE target created, with Minimum Deployments matching the app
-
AppsOnAir-AppPush-ContentExtis linked to the NCE only -
MainInterface.storyboarddeleted, andNSExtensionPrincipalClassset -
UNNotificationExtensionCategoryequals theaps.categoryyou send
Log Levels
Set before initialize():
.none- Silent (default for production).error- Errors only.warn- Warnings.info- General info.debug- Debug info.verbose- All messages (use during development)