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    Discussions

Corona SDK Setup

Instructions for adding the OneSignal SDK to your Corona app for iOS, Android, and derivatives like Amazon

Required For Setup

  • A OneSignal account, if you do not already have one
  • Your OneSignal App ID, available in Settings > Keys & IDs in the OneSignal dashboard

Generate Credentials

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

1. Add OneSignal to your Account

1.1 Login into your account on Corona's site and bring up the OneSignal plugin on the Corona plugin directory.

1.2 Click the "FREE" button.

1.3 Click "Finish Checkout".

2. Add OneSignal to Your Project

2.1 Update the build.settings file in the Corona project folder to contain the following inside of settings = {.

plugins =
{
    ["plugin.OneSignal"] =
    {
        publisherId = "com.onesignal",
    }
}

2.2 iOS - Add the following line inside of 'plist = {' in build.settings.

UIBackgroundModes = {"remote-notification"},

3. Add Required Code

3.1 At the top of main.lua, place the following code.

-- This function gets called when the user opens a notification or one is received when the app is open and active.
-- Change the code below to fit your app's needs.
function DidReceiveRemoteNotification(message, additionalData, isActive)
    if (additionalData) then
        if (additionalData.discount) then
            native.showAlert( "Discount!", message, { "OK" } )
            -- Take user to your app store
        elseif (additionalData.actionSelected) then -- Interactive notification button pressed
            native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} )
        end
    else
        native.showAlert("OneSignal Message", message, { "OK" } )
    end
end

local OneSignal = require("plugin.OneSignal")
-- Uncomment SetLogLevel to debug issues.
-- OneSignal.SetLogLevel(4, 4)
OneSignal.Init("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "############", DidReceiveRemoteNotification)

3.2 Replace XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX with your Application Key, available in the OneSignal dashboard under Settings > Keys & IDs.

3.3 Android - Replace ############ with your Google Project number.

3.4 Amazon - Put your app_key.txt (from Generate an Amazon API Key instructions above) into the root of your Corona project folder.

When you build your app, change the Target App Store setting to Amazon.

Troubleshooting

If you get an error saying "Plugin_OneSignal not found", make sure the plugin shows as active on your account on the Corona's plugin directory page.

Also, make sure the same account you used on the Corona plugin directory is the same account you signed into in the Corona Simulator.

If that is correct, you may need to wait 30 minutes to 1 hour for OneSignal to become active on your account. Feel free to contact us or Corona if the error persists.


Setup SDK for Corona Native

Generate Credentials

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

1. Add OneSignal to Your Project

1.1 Update the build.settings file in the Corona project folder to contain the following inside of settings = {.

plugins =
{
    ["plugin.OneSignal"] =
    {
        publisherId = "com.onesignal",
    }
}

2.1A Android - Run android/download_plugins.sh located in your app folder. You can find more details about this step in Corona's blog post.

2.1B iOS - 1. Open your project in Xcode. 2. In the Xcode toolbar, click on the active scheme button, and select Download Plugins. You can find more details about this step in Corona's Blog post.

2. Add Required Code

2.1 At the top of main.lua, place the following code.

-- This function gets called when the user opens a notification or one is received when the app is open and active.
-- Change the code below to fit your app's needs.
function DidReceiveRemoteNotification(message, additionalData, isActive)
    if (additionalData) then
        if (additionalData.discount) then
            native.showAlert( "Discount!", message, { "OK" } )
            -- Take user to your app store
        elseif (additionalData.actionSelected) then -- Interactive notification button pressed
            native.showAlert("Button Pressed!", "ButtonID:" .. additionalData.actionSelected, { "OK"} )
        end
    else
        native.showAlert("OneSignal Message", message, { "OK" } )
    end
end

local OneSignal = require("plugin.OneSignal")
OneSignal.Init("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "############", DidReceiveRemoteNotification)

2.2 Replace XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX with your Application Key, which you can find in the OneSignal dashboard under Settings > Keys & IDs.

2.3 Replace ############ with your Google Project number if your app is for Android.

3. Add Plugin to iOS

3.1 Add Required Capabilities
3.1A Select the root project, and Under Capabilities, enable "Push Notifications"
3.1B Next, enable "Background Modes" and check "Remote Notifications"

3.2 Open your -Info.p file add the key CoronaDelegates as an Array type. Add an entry as OneSignalCoronaDelegate.

4. Add Plugin to Android or Amazon

4.1 Add the following permissions to your AndroidManifest.xml file.

<permission android:name="COM.YOUR.PACKAGE_NAME.permission.C2D_MESSAGE"
            android:protectionLevel="signature"/>
<uses-permission android:name="COM.YOUR.PACKAGE_NAME.permission.C2D_MESSAGE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

 <!-- Use to restore notifications the user hasn't interacted with.
         They could be missed notifications if the user reboots their device if this isn't in place.
    -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

4.2 In the application tag, add the following.

<application ...>
  <receiver android:name="com.onesignal.NotificationOpenedReceiver" />

  <service android:name="com.onesignal.GcmIntentService" />
  <service android:name="com.onesignal.GcmIntentJobService"
           android:permission="android.permission.BIND_JOB_SERVICE" />

  <service android:name="com.onesignal.RestoreJobService"
           android:permission="android.permission.BIND_JOB_SERVICE" />

  <service android:name="com.onesignal.RestoreKickoffJobService"
           android:permission="android.permission.BIND_JOB_SERVICE" />

  <service android:name="com.onesignal.SyncService" android:stopWithTask="true" />
  <service android:name="com.onesignal.SyncJobService"
           android:permission="android.permission.BIND_JOB_SERVICE" />

  <activity android:name="com.onesignal.PermissionsActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

  <service android:name="com.onesignal.NotificationRestoreService" />

  <receiver android:name="com.onesignal.BootUpReceiver">
    <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
  </receiver>
  <receiver android:name="com.onesignal.UpgradeReceiver" >
    <intent-filter>
      <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
  </receiver>
</application>

4.3 Optional If you need receive other GCM messages through Corona (like Helpshift), then add the following to your AndroidManifest.xml.

<receiver
  android:name="com.onesignal.CoronaGCMFilterProxyReceiver"
  android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="COM.YOUR.PACKAGE_NAME" />
    </intent-filter>
</receiver>

4.4 Replace COM.YOUR.PACKAGE_NAME with your full package name from the last 2 steps.

4.5 In Eclipse, open your android/project.properties and add the following.

android.library.reference.2=relative_path/google-play-services_lib

The path you add MUST be relative and not absolute, and should look something like this:

../../../android-sdks/extras/google/google_play_services/libproject/google-play-services_lib

4.6 In Eclipse, build your app. If you get an error about build.xml missing, then cd to the google-play-services_lib folder in the Android SDK and run:

android update lib-project --path . --target android-10

Proguard

If you have Proguard enabled on your project, you must add the following lines to your Proguard config file. The default filename is proguard-project.txt.

-dontwarn com.onesignal.**
-dontwarn com.gamethrive.**

5. Add Plugin to Amazon

5.1 Follow all the steps from Add Plugin to Android

5.2 Add the following permission to your AndroidManifest.xml

<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="COM.YOUR.PACKAGE_NAME.permission.RECEIVE_ADM_MESSAGE" />

5.3 In the application tag, add the following:

<application ...>
  <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false" xmlns:amazon="http://schemas.amazon.com/apk/res/android" />

  <service android:name="com.onesignal.ADMMessageHandler" android:exported="false" />
  <receiver
            android:name="com.onesignal.ADMMessageHandler$Receiver"
            android:permission="com.amazon.device.messaging.permission.SEND" >

    <intent-filter>
      <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
      <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
      <category android:name="COM.YOUR.PACKAGE_NAME" />
    </intent-filter>

  </receiver>
</application>

4.4 Replace COM.YOUR.PACKAGE_NAME with your full package name from the last 2 steps.

4.5. Put your app_key.txt into the root of your Corona project folder. To get this file, follow our Generate an Amazon API Key instructions.

Updated 4 months ago



Corona SDK Setup


Instructions for adding the OneSignal SDK to your Corona app for iOS, Android, and derivatives like Amazon

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.