Advanced Integration
Disable automatic integration, manually forward app delegate methods, and configure URL allowlists for the Airship SDK.
Configuring Airship via plist file
If no config is provided to takeOff programmatically, Airship will default to loading config from the AirshipConfig.plist file in your application’s bundle. This can be useful for apps with multiple build variants, or for keeping credentials out of version control.
Sample AirshipConfig.plist file:
<?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>detectProvisioningMode</key>
<true/>
<key>developmentAppKey</key>
<string>Your Development App Key</string>
<key>developmentAppSecret</key>
<string>Your Development App Secret</string>
<key>productionAppKey</key>
<string>Your Production App Key</string>
<key>productionAppSecret</key>
<string>Your Production App Secret</string>
</dict>
</plist>The keys used in the AirshipConfig.plist file match the field names in
with
AirshipConfig
.
If your app uses Airship’s EU cloud site, add the site key:
<key>site</key>
<string>EU</string>Manual Integration
By default, the Airship SDK automatically integrates with your app using method swizzling. This allows the SDK to intercept app delegate messages and forward them automatically, so you don’t need to implement push-related UIApplicationDelegate or UNUserNotificationCenterDelegate protocol methods.
For most applications, automatic integration works out of the box. However, if you have custom app delegate requirements or prefer explicit control over method forwarding, you can disable automatic integration and handle it manually.
Disabling automatic integration
Set
AirshipConfig.isAutomaticSetupEnabled
to false in your Airship config during takeOff:
Disabling automatic integration
var config = AirshipConfig()
config.isAutomaticSetupEnabled = false
try! Airship.takeOff(config)UAConfig *config = [UAConfig config];
config.isAutomaticSetupEnabled = NO;
[UAirship takeOff:config error:&airshipError];Forwarding app delegate methods
When automatic integration is disabled, you must forward the appropriate app delegate methods to the Airship SDK.
Manual integration
UIApplicationDelegate methods:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Set up the UNUserNotificationCenter delegate
UNUserNotificationCenter.current().delegate = self
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
AppIntegration.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
AppIntegration.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
return await AppIntegration.application(application, didReceiveRemoteNotification: userInfo)
}UNUserNotificationCenterDelegate methods:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping @Sendable () -> Void
) {
// Call through to Airship. The completion handler version is called on the main actor.
// It's important to use the `completionHandler` version and not the async one, or it
// will be called on a background thread and Airship might not receive the event in time
// to count the direct open.
MainActor.assumeIsolated {
AppIntegration.userNotificationCenter(
center,
didReceive: response,
withCompletionHandler: completionHandler
)
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
return await AppIntegration.userNotificationCenter(center, willPresent: notification)
}UIApplicationDelegate methods:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set up the UNUserNotificationCenter delegate
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[UAAppIntegration application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[UAAppIntegration application:application didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[UAAppIntegration application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}UNUserNotificationCenterDelegate methods:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[UAAppIntegration userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
[UAAppIntegration userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}URL allowlist
The URLAllowList controls which URLs the Airship SDK is able to act on. The SDK divides up usages of URLs into two different scopes:
SCOPE_OPEN_URL: Only URLs allowed for this scope can be opened from an action, displayed in landing page, or displayed in an HTML in-app message. Defaults to allowing all URLs if not specified in the config.SCOPE_JAVASCRIPT_INTERFACE: These URLs are checked before the Airship JavaScript interface is injected into the webview. Defaults to any Airship originated URLs.
Allowed URLs should be provided when configuring the Airship Config during takeOff.
URL allowlist configuration
var config = AirshipConfig()
// Allow all URLs for both scopes
config.urlAllowList = ["*"]
// Or configure specific scopes:
config.urlAllowListScopeOpenURL = ["https://example.com/*", "https://*.youtube.com/*"]
config.urlAllowListScopeJavaScriptInterface = ["https://example.com/*"]
try! Airship.takeOff(config)UAConfig *config = [UAConfig config];
// Allow all URLs for both scopes
config.urlAllowList = @[@"*"];
// Or configure specific scopes:
config.urlAllowListScopeOpenURL = @[@"https://example.com/*", @"https://*.youtube.com/*"];
config.urlAllowListScopeJavaScriptInterface = @[@"https://example.com/*"];
[UAirship takeOff:config error:&airshipError];<pattern> := '*' | <scheme>'://'<host>/<path> | <scheme>'://'<host> | <scheme>':/'<path> | <scheme>':///'<path>
<scheme> := <any char combination, '*' are treated as wild cards>
<host> := '*' | '*.'<any char combination except '/' and '*'> | <any char combination except '/' and '*'>
<path> := <any char combination, '*' are treated as wild cards>Categories