Getting Started

This is a developers' guide for setting up the Airship SDK for React Native apps.

The Airship React Native module allows a developer to integrate push notification services with React Native apps targeting both Android and iOS. This module is designed to be cross-platform, and applications making use of it can leverage the same code on both platforms.

Resources

Requirements

  • React Native >= 0.44.0
  • React Native cli >= 2.0.1

iOS

  • Xcode 10+
  • Airship SDK 10+

Android

  • minSdkVersion 16+
  • compileSdkVersion 28+

Android Setup

1) Install and link the urbanairship-react-native module.

react-native install urbanairship-react-native react-native link urbanairship-react-native

2) Create the airshipconfig.properties file in the applications main/assets.

Example airshipconfig.properties
developmentAppKey = Your Development App Key
developmentAppSecret = Your Development App Secret

productionAppKey = Your Production App Key
productionAppSecret = Your Production Secret

notificationIcon = ic_notification
notificationAccentColor = #ff0000

3) Download the Android Firebase configuration file google-services.json from the application's Firebase console into the root directory at android/app/google-services.json.

If your react-native application does not have an associated app in the Firebase console, follow the FCM setup instructions to set one up.

iOS Setup

1) Install and link the urbanairship-react-native module.

react-native install urbanairship-react-native react-native link urbanairship-react-native

2) Install cocoapods.

$ gem install cocoapods

3) Generate a Pod file if needed.

$ pod init

4) Update the app's Podfile to include the Airship SDK.

pod 'UrbanAirship-iOS-SDK', '~>11.0' # Optional: uncomment to install AirshipLocationKit # pod 'UrbanAirship-iOS-Location', '~>11.0'

5) Update your pods.

$ pod install

5) Open your apps project in the generated .xcworkspace file, add the following capabilities: - Push Notification - Background Modes > Remote Notifications

6) Create a plist AirshipConfig.plist and include it in your application’s target.

Example AirshipConfig.plist
<?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>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>

Notification Service Extension

In order to take advantage of iOS 10 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.

Send Your First Push Notification

At this point in the guide, if you followed all the steps above you should be ready to send a test push notification to verify everything is set up properly.

Before sending a push, you must enable user notifications. The module does not enable user notifications by default in order to avoid prompting the user for permissions. But for a testing purposes, you can enable user notifications as soon as the application is ready. You may also want to set default foreground presentation options to display the notification in the foreground on iOS 10. On older iOS devices, make sure you background the app before sending the push.

Enable user notifications
import {
  UrbanAirship,
  UACustomEvent,
} from 'urbanairship-react-native'


class SampleApp extends Component {

  constructor(props) {
    super(props);

    UrbanAirship.setUserNotificationsEnabled(true)
  }

  ...
}