Extend Airship
How to extend the Airship React Native module to access native iOS and Android SDK features not exposed through the React Native API.
You can provide a plugin extender that will be automatically loaded for the app. The extender can be used to modify the Airship config before SDK initialization and to access the underlying native SDK once Airship is ready. This gives the app a chance to customize parts of Airship that are not configurable through React Native, such as setting up iOS Live Activities and Android Live Updates.
iOS
For iOS, create a Swift file named AirshipPluginExtender.swift and needs to be included in the main app target. Make sure the class has the @objc(AirshipPluginExtender) annotation and inherits AirshipPluginExtenderProtocol.
import Foundation
import AirshipKit
import AirshipFrameworkProxy
import ActivityKit
@objc(AirshipPluginExtender)
public class AirshipPluginExtender: NSObject, AirshipPluginExtenderProtocol {
public static func onAirshipReady() {
// Called when Airship is ready on the MainActor
}
public static func extendConfig(config: inout AirshipConfig) {
// Called to extend the AirshipConfig before SDK initialization
}
}Android
Create a file in the App’s src directory named AirshipExtender. It needs to extend com.urbanairship.android.framework.proxy.AirshipPluginExtender and have an empty constructor.
// Replace with your package
package com.example
import android.content.Context
import androidx.annotation.Keep
import com.urbanairship.AirshipConfigOptions
import com.urbanairship.UAirship
import com.urbanairship.android.framework.proxy.AirshipPluginExtender
@Keep
public final class AirshipExtender: AirshipPluginExtender {
override fun onAirshipReady(context: Context, airship: UAirship) {
// Called when Airship is ready on a background thread.
// Avoid doing long running, blocking work or it will delay Airship
}
override fun extendConfig(
context: Context,
configBuilder: AirshipConfigOptions.Builder
): AirshipConfigOptions.Builder {
// Called to extend the AirshipConfig before SDK initialization
return configBuilder
}
}Register the extender in the manifest:
<application ...>
<meta-data android:name="com.urbanairship.plugin.extender"
android:value="com.example.AirshipExtender" />
<!-- ... -->
</application>