Cordova Plugin Setup

How to install the Airship Cordova plugin.

Requirements

  • cordova >= 10.0.0
  • cordova-ios >= 6.1.0
  • cordova-android >= 9.0.0
  • cococapods >= 1.9

iOS

iOS only: Add your Apple Developer Account Team ID to the build.json.

{
  "ios": {
    "debug": {
    "developmentTeam": "XXXXXXXXXX"
    },
    "release": {
      "developmentTeam": "XXXXXXXXXX"
    }
  }
}

Your iOS builds will need to reference the build.json using Cordova’s --buildConfig flag.

Android

Android only: Add a reference to your google-services.json file in the app’s config.xml

<platform name="android">
    ...
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>

Setup

Install the plugin using Cordova CLI:

cordova plugin add urbanairship-cordova

Initialize Airship

Before you can access any of the module’s API, the Airship module needs to be initialized. This can be accomplished by calling takeOff when the device is ready.

Calling takeOff
// TakeOff
UAirship.takeOff({
  production: {
    appKey: "<APP_KEY>",
    appSecret: "<APP_SECRET>"
  },
  development: {
    appKey: "<APP_KEY>",
    appSecret: "<APP_SECRET>"
  },
  site: "EU" // Optional. Either "EU" or "US". Defaults to "US".
})

// Configure Android
UAirship.setAndroidNotificationConfig({
  icon: "ic_notification",
  largeIcon: "ic_notification_large",
  accentColor: "#FF0000"
})

// Configure iOS
UAirship.setPresentationOptions(
  UAirship.presentationOptions.sound | UAirship.presentationOptions.alert
)

Takeoff can be called multiple times, but the config passed in takeOff won’t be applied until the next app init.

iOS Notification Service Extension

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

Follow the steps in the iOS Notification Service Extension Guide.