OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Support
discard

Search results for "{{ search.query }}"

No results found for "{{search.query}}".

Ionic SDK Setup

OneSignal Ionic SDK Setup Guide. Works with iOS, Android (and derivatives like Amazon) and Windows Phone 8.1.

For Developers

Generate Credentials

Before setting up the Cordova SDK, you must generate the appropriate credentials for the platform(s) you are releasing on:

iOS - Generate an iOS Push Certificate

Android - Generate a Google Server API Key

Amazon - Generate an Amazon API Key

Windows Phone 8.1 - Generate a Windows Phone Package SID and Secret


1. Import OneSignal Plugin

Please follow step 1A or 1B based how you build your app.

1A. Import from the Terminal

Run the following from your project directory.

ionic plugin add onesignal-cordova-plugin
Ionic Lab does not have a UI to add 3rd party plugins.
Please run the following from your project directory from a terminal:

ionic plugin add onesignal-cordova-plugin

2. Add required code

2.1. Add the following to your <project-dir>/www/js/app.js. (app.ts for Ionic2)

// Add the following to your existing ready fuction.

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Enable to debug issues.
  // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
  
  var notificationOpenedCallback = function(jsonData) {
    console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
  };

  window.plugins.OneSignal.init("b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
                                 {googleProjectNumber: "703322744261"},
                                 notificationOpenedCallback);
  
  // Show an alert box if a notification comes in when the user is in your app.
  window.plugins.OneSignal.enableInAppAlertNotification(true);
  });
})
// Add the following to your existing ready fuction.

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Enable to debug issues.
  // window["plugins"].OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
  
  var notificationOpenedCallback = function(jsonData) {
    console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
  };

  window["plugins"].OneSignal.init("b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
                                 {googleProjectNumber: "703322744261"},
                                 notificationOpenedCallback);
  
  // Show an alert box if a notification comes in when the user is in your app.
  window["plugins"].OneSignal.enableInAppAlertNotification(true);
  });
})

2.2 Update the 3 init parameters

Replace b2f7f966-d8cc-11e4-bed1-df8f05be55ba with your OneSignal AppId.

Replace 703322744261 with your Google Project Number.

  • (If your app isn't for Android you can replace the number with a blank string).

Change the code in the notificationOpenedCallback function to your liking.

  • The function is called when you tap on a notification
  • Callback is option if you only want the app to open when a notification is tapped on.

3. Android

3.1 Open the Android SDK Manager.

3.2 Make sure to install and update the following under Extras:

  • Android Support Repository
  • Google Repository

3.3 Follow the Custom Notification Icons instructions below to create a small notification icon required for Android 5.0+ devices.


4. Amazon ADM

Place your api_key.txt file into your <project-dir>/platforms/android/assets/ folder.

To create an api_key.txt for your app follow our Generate an Amazon API Key


5. iOS

5.1 No extra steps, you're all set if you already setup your provisioning profile and push certificate.


6. Windows Phone 8.1 (WP8.1)

Your app does not have to be published however, you must have it created on the Windows Dev Center. Follow our Windows Phone Project SID & Secret setup if you have not done this yet.

6.1 Run cordova build windows and open the .sln in <project-root>/platforms/windows/

6.2 Under the Windows Phone 8.1 project double click on Package.appxmanifest then select the "Application" tab and scroll down to the "Notifications:" section. Change "Toast capable:" to Yes.

6.3 Right click on your VS project and select Store>Associate App with the Store...

6.4 Click Next and sign into your Microsoft account.

6.5 Select your app and press Next.

6.6. Lastly press Associate.


Custom Notification Sounds

iOS

1. Open the Xcode project from <project-root>/platforms/ios/project-name.xcodeproj.

2. Drag and drop your audio files into the Resource folder.

3. When sending a notification use "filename.extension" in the custom iOS sound field.

Android

1. Copy your audio files to <project-root>/platforms/android/res/raw/. (Create the raw folder if you do not have one).

2. When sending a notification use "filename" (without the extension) in the custom Android sound field.


Custom Notification Icons

Android and Amazon

1. See our small, large, and big picture sections in our Android Notification Customizations guide.

2. The files noted in the guide above need to go into your <project-root>/platforms/android/res folder.
Note: For the small icon you will need a drawable folder for each screen density as noted in the link.


SDK API

Check out our Ionic SDK for more OneSignal functions.

Push Notification Testing Requirements

  • iOS - Must test on a real device, Simulator does not support Apple push notifications.
  • Android
    • You MUST build and install your app's APK.
    • You may use an emulator but it must have an updated version of Google Play services installed.

Troubleshooting

If you run into any errors see Troubleshooting Cordova Variants, our our general Troubleshooting section.

Ionic SDK Setup

OneSignal Ionic SDK Setup Guide. Works with iOS, Android (and derivatives like Amazon) and Windows Phone 8.1.

For Developers