• Stars
    star
    142
  • Rank 257,096 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Urban Airship integration with Apache Cordova

Urban Airship Cordova Plugin

This plugin supports Cordova apps running on both iOS and Android.

Resources:

Issues

Please visit http://support.urbanairship.com/ for any issues integrating or using this plugin.

Requirements:

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

iOS:

Android

  • minSdkVersion 21+
  • compileSdkVersion and targetSdkVersion 33+
  • Gradle Plugin version 3.0.0+
  • Java 8
  • Android FCM Setup
Jetpack / AndroidX

This plugin requires modern Jetpack libraries (AndroidX). Enable AndroidX in your config.xml:

<preference name="AndroidXEnabled" value="true" />

Quickstart

  1. Install this plugin using Cordova CLI:

     cordova plugin add urbanairship-cordova
    
  2. (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>
  1. (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.

  2. Initialize Urban Airship

    Either call takeOff when the device is ready:

     // TakeOff
     UAirship.takeOff({
       production: {
         appKey: "<APP_KEY>",
         appSecret: "<APP_SECRET>"
       },
       development: {
         appKey: "<APP_KEY>",
         appSecret: "<APP_SECRET>"
       },
       site: "US"
     })
    
     // Configure Android
     UAirship.setAndroidNotificationConfig({
       icon: "ic_notification",
       largeIcon: "ic_notification_large",
       accentColor: "#FF0000"
     })
    
     // Configure iOS
     UAirship.setPresentationOptions(
       UAirship.presentationOptions.sound | UAirship.presentationOptions.alert
     )
    

    Alternatively you can configure Urban Airship through config.xml and it will takeOff automatically.

     <!-- Urban Airship app credentials -->
     <preference name="com.urbanairship.production_app_key" value="Your Production App Key" />
     <preference name="com.urbanairship.production_app_secret" value="Your Production App Secret" />
     <preference name="com.urbanairship.development_app_key" value="Your Development App Key" />
     <preference name="com.urbanairship.development_app_secret" value="Your Development App Secret" />
    
     <!-- Optional -->
     <!-- If the app is in production or not. If not set, Urban Airship will auto detect the mode. -->
     <preference name="com.urbanairship.in_production" value="true | false" />
    
     <!-- Urban Airship development log level defaults to debug -->
     <preference name="com.urbanairship.development_log_level" value="none | error | warn | info | debug | verbose" />
    
     <!-- Urban Airship production log level defaults to error -->
     <preference name="com.urbanairship.production_log_level" value="none | error | warn | info | debug | verbose" />
    
     <!-- Enables/disables auto launching the message center when the corresponding push is opened. -->
     <preference name="com.urbanairship.auto_launch_message_center" value="true | false" />
    
     <!-- Urban Airship SDK Site (US or EU) defaults to US) -->
     <preference name="com.urbanairship.site" value="US" />
    
     <!-- Android Notification Settings -->
     <preference name="com.urbanairship.notification_icon" value="ic_notification" />
     <preference name="com.urbanairship.notification_large_icon" value="ic_notification_large" />
     <preference name="com.urbanairship.notification_accent_color" value="#0000ff" />
    
     <!-- iOS Foreround Presentation Options -->
     <preference name="com.urbanairship.ios_foreground_notification_presentation_alert" value="true | false"/>
     <preference name="com.urbanairship.ios_foreground_notification_presentation_badge" value="true | false"/>
     <preference name="com.urbanairship.ios_foreground_notification_presentation_sound" value="true | false"/>
    
     <!-- iOS Auto Clear Badge -->
     <preference name="com.urbanairship.clear_badge_onlaunch" value="true | false" />
    
     <!-- Deployment target must be >= iOS 11  -->
     <preference name="deployment-target" value="11.0" />
    

    UrbanAirship.takeOff can be called multiple times but any changes to the app credentials will not apply until the next app start.

  3. Enable user notifications:

     // Enable user notifications (will prompt the user to accept push notifications on iOS)
     UAirship.setUserNotificationsEnabled(true, function (enabled) {
         console.log("User notifications are enabled! Fire away!")
     })
    
  4. (Optional) Listen for events:

     document.addEventListener("urbanairship.registration", onRegistration)
     document.addEventListener("urbanairship.push", onPushReceived)
     document.addEventListener("urbanairship.notification_opened", notificationOpened)
     document.addEventListener("urbanairship.deep_link", handleDeepLink)
    
  5. (Optional) Add platform-specific custom notification button groups resource files to config.xml:

  <!-- Optional: include custom notification button groups in XML format -->
  <platform name="android">
      ...
      <resource-file src="ua_custom_notification_buttons.xml" target="app/src/main/res/xml/ua_custom_notification_buttons.xml" />
  </platform>

  ...

  <!-- Optional: include custom notification categories in plist format -->
  <platform name="ios">
      ...
      <resource-file src="UACustomNotificationCategories.plist" />
  </platform>

Common CocoaPod Installation issues

Errors related to CocoaPods can be difficult to diagnose, because the cordova command line tool will often exit with a status code without providing the necessary context. You may run into something like the following when attempting to add the plugin to your ios project:

Installing "urbanairship-cordova" for ios
Failed to install 'urbanairship-cordova':Error: pod: Command failed with exit code 1
    at ChildProcess.whenDone (/Users/xxxxx/xxxxx/test/platforms/ios/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:818:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
Error: pod: Command failed with exit code 1

This exit code can have a few underlying causes. One is that the local spec repo may be out of date, in which case CocoaPods may be unable to find the version of the native SDK being installed. To resolve this, run the command pod repo update and try re-adding the plugin. You would only need to run pod repo update if you have the specs-repo already cloned on your machine through pod setup.

Another potential cause involves minimum deployment targets. The Airship iOS SDK supports the three most recent iOS versions, and thus to install the plugin, your app must set its minimum deployment target accordingly, in config.xml. As an example, see the deployment target in the provided sample config. Setting this value correctly should cause Cordova to generate a Podfile in the ios subdirectory of your application with the same value for its platform version. If the minimum deployment target is not specified, cordova will choose its own default value, which may be incorrect, and adding the plugin will fail with exit code 1.

There are also known issues in Cordova that can cause the platform version in ios/Podfile to be overwritten with Cordova's default version. In both cases, doing the following will fix the issue:

  • Update config.xml with the correct minimum deployment target, if needed.
  • cordova plugin remove urbanairship-cordova
  • cordova platform remove ios
  • cordova platform add ios
  • cordova plugin add urbanairship-cordova

iOS Notification Service Extension

In order to take advantage of iOS notification attachments, such as images, animated gifs, and video, you will need to create a notification service extension by following the iOS Notification Service Extension Guide.

Sample

A sample can be found in the Example directory.

  1. Add your UA credentials to the config_sample.xml file in the root directory and save.
  2. Run the script with the command ./scripts/create_sample.sh PROJECT_PATH PROJECT_NAME
  3. cd to the newly-created project directory, e.g. sample/test
  4. Build the platform you want to test.
    • iOS
      1. Build with command cordova build ios --emulator
      2. After successful build, connect an iOS device to test
      3. Run on device with command cordova run ios --device --developmentTeam=XXXXXXXXXX
        • Please refer to "Signing an App" for more information about code signing.
    • Android
      1. Build with command cordova build android in test directory
      2. After successful build, connect an android device to test
      3. Test with command cordova run android

More Repositories

1

ios-library

Urban Airship iOS SDK
Swift
474
star
2

datacube

Multidimensional data storage with rollups for numerical data
Java
264
star
3

ruby-library

A Ruby wrapper for the Urban Airship API.
Ruby
201
star
4

frock

A plugin-based tool for running fake HTTP and socket services
JavaScript
140
star
5

techladder

Job titles and descriptions for UA engineering
Makefile
113
star
6

android-library

Urban Airship Android SDK
Kotlin
109
star
7

react-native-airship

Airship React Native module
TypeScript
87
star
8

python-library

A Python library for using the Airship APIs for push notifications, reporting and other message types
Python
82
star
9

ios-phonegap-plugin

This repo is deprecated. Please see: https://github.com/urbanairship/phonegap-ua-push
JavaScript
69
star
10

statshtable

Java
45
star
11

drive.js

Drive.js makes testing JavaScript applications easy, wherever they live
JavaScript
43
star
12

php-library2

Urban Airship PHP Library
PHP
38
star
13

android-samples

DEPRECATED - Use https://github.com/urbanairship/android-library instead
Java
33
star
14

java-library

Java client library for the Urban Airship API
Java
32
star
15

mvn-python-packaging

A code sample and article describing how maven can be used to build python packages.
Python
32
star
16

beanstalk-munin

Munin plugins for Beanstalkd written in Python
Python
30
star
17

ios-samples

A collection of samples using the Urban Airship ios-library
Objective-C
26
star
18

aerostat

Cloud Naming Client/Service
Python
25
star
19

hbackup

Java
22
star
20

go-iapclient

A Google Cloud Platform Identity Aware Proxy authentication library for Golang
Go
20
star
21

airship-flutter

Flutter integration
Dart
17
star
22

ua-unity-plugin

C#
15
star
23

ua-ios-pod

a project for staging, testing and managing Urban Airship's cocoapod situation
Objective-C
15
star
24

pubsubsuperfeedr

Simple Python library to interface with Superfeedr's pubsubhubbub interface.
Python
10
star
25

titanium-module

Urban Airship Titanium module
Swift
9
star
26

urbanairship-xamarin

Urban Airship Xamarin Libraries
C#
9
star
27

node-connect-client

A node client for connecting to the Urban Airship Connect API.
JavaScript
8
star
28

passtools-api

Official documentation and resources for the PassTools API
8
star
29

pykafkap

Python Kafka Producer
Python
7
star
30

connect-java-library

Java client library for Urban Airship Connect
Java
6
star
31

objectstate

Streaming state management for node and the browser
JavaScript
6
star
32

django-subforms

An implementation of Hierarchical forms and form-to-model mapping.
Python
5
star
33

django-finial

Hierarchical template overriding on a per request basis.
Python
5
star
34

bb-push-sample-os5

BlackBerry push notification sample application, OS 5.0 and up
Java
5
star
35

android-gimbal-adapter

The Android Gimbal adapter for Urban Airship
Java
5
star
36

django-mithril

IP (v4 and v6) Whitelisting for Django
Python
5
star
37

connect-json-schema

JSON Schema for connect events
4
star
38

bb-push-sample-os4

BlackBerry push notification sample application, OS 4.x compatible
Java
4
star
39

passtools-ruby

Official Ruby SDK for the PassTools API
Ruby
4
star
40

kiddiepool

Python Client Driver Pool
Python
4
star
41

tap-set-exit

Sets the correct exit code based on tap output.
JavaScript
4
star
42

dedupe-stream

A stream that prevents consecutive duplicate emissions.
JavaScript
3
star
43

sarlacc-pit

Library for maintaining a complete in-memory copy of a remote data source.
Java
3
star
44

android-automator-utils

This project contains utilities that are used for UI Automation testing.
Java
3
star
45

google-v3-geocoder

Geokit::Geocoder subclass for interacting with google's v3 geocoder
3
star
46

ios-gimbal-adapter

The iOS Gimbal adapter for Urban Airship
Swift
3
star
47

ua-api-utils

Urban Airship API Utilities
Python
2
star
48

frock-middleware-delay

Delay middleware for frock. Introduce some latency.
JavaScript
2
star
49

passtools-java

Official Java SDK for the PassTools API
Java
2
star
50

object-cursor-stream

de-duped keypath stream
JavaScript
2
star
51

frock-static

A static file server for frock
JavaScript
2
star
52

apptimize-ios-kit

Swift
2
star
53

passtools-python

Official Python SDK for the PassTools API
Python
2
star
54

api-specs

OpenAPI specs for Airship APIs
2
star
55

logbot

IRC Logging Bot
Python
2
star
56

frock-proxy

A proxy plugin for frock
JavaScript
2
star
57

accengage-mobile-react-native

React Native module wrapping Android and iOS SDKs
Objective-C
2
star
58

padlocker-client

Encryption key dispersion service - Client
Python
2
star
59

cordova-gimbal-bridge

Gimbal Phongap plugin that uses the GimbalAdapter
Objective-C
2
star
60

streaming-set

A stream which adds objects written to it to a set, and then emits the updated array.
JavaScript
2
star
61

mongotools

Python tools for working with MongoDB
Python
1
star
62

connect-python-library

Python client library for Urban Airship Connect
Python
1
star
63

apptimize-flutter

Apptimize Flutter Plugin for iOS and Android
Dart
1
star
64

urbanairship-accengage-cordova

DEPRECATED
1
star
65

accengage-ios-sdk-releases

The Accengage iOS Framework Releases
1
star
66

capacitor-airship

TypeScript
1
star
67

cordova-gimbal-sdk

Objective-C
1
star
68

ios-pod-specs

Repository for Accengage CocoaPods specifications.
Ruby
1
star
69

android-ga-tracker

Android extension to the Google Analytics SDK
Java
1
star
70

react-native-gimbal-adapter

Objective-C
1
star
71

apptimize-qa-console-ios

Preview variants in different combinations from all of your active feature flags and experiments.
Swift
1
star
72

airship-mobile-framework-proxy

Kotlin
1
star
73

accengage-android-sdk-samples

Java
1
star
74

react-native-acc-fcm

Accengage FCM Plugin for React Native
Java
1
star
75

reach-python-library

Python client library for Urban Airship Reach
Python
1
star
76

airship-dotnet

C#
1
star
77

break-the-intranet

Hack week / Intranet
JavaScript
1
star
78

apptimize-qa-console-android

Java
1
star
79

accengage-android-lib-sample

Java
1
star
80

analytics-swift-apptimize

Swift
1
star
81

cordova-firebase-app-init

Java
1
star
82

ua-extensions

Urban Airship extensions repository houses drop in classes that provide additional functionality for the Urban Airship SDK
Objective-C
1
star
83

padlocker-server

Encryption key dispersion service - Server
JavaScript
1
star
84

ios-segment-integration

A simple way to integrate Urban Airship and Segment.
Objective-C
1
star