<commit_before># React Native OneSignal

React Native Push Notifications support with OneSignal integration.


[![npm version](https://img.shields.io/npm/v/react-native-onesignal.svg?style=flat-square)](https://www.npmjs.com/package/react-native-onesignal)
[![npm downloads](https://img.shields.io/npm/dm/react-native-onesignal.svg?style=flat-square)](https://www.npmjs.com/package/react-native-onesignal)

<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->

- [React Native OneSignal](#react-native-onesignal)
	- [Installation](#installation)
	- [Android Installation](#android-installation)
	- [iOS Installation](#ios-installation)
		- [Importing The Library](#importing-the-library)
		- [Adding the Code](#adding-the-code)
	- [Android Usage](#android-usage)
	- [iOS Usage](#ios-usage)
	- [API](#api)
		- [Handling Notifications](#handling-notifications)
		- [Sending and Getting OneSignal Tags](#sending-and-getting-onesignal-tags)
		- [Getting Player ID and Push Token](#getting-player-id-and-push-token)
		- [Enable Vibration](#enable-vibration)
		- [Enable Sound](#enable-sound)
		- [Enable Notification When App Active](#enable-notification-when-app-active)
		- [Enable In-App Alert Notification](#enable-in-app-alert-notification)
		- [Change User Subscription Status](#change-user-subscription-status)
		- [Post Notification (Peer-to-Peer Notifications)](#post-notification-peer-to-peer-notifications)
		- [Prompt Location (Android Only)](#prompt-location-android-only)
		- [Request Push Notification Permissions](#request-push-notification-permissions)
		- [Register For Push Notifications](#register-for-push-notifications)
	- [FAQ / Repeating Issues](#faq-repeating-issues)
		- [Issue 1 - Multiple dex files define:](#issue-1-multiple-dex-files-define)
		- [Issue 2 - Multiple dex files define (Again):](#issue-2-multiple-dex-files-define-again)
	- [CREDITS](#credits)
	- [TODO](#todo)

<!-- /TOC -->

## Installation
`npm install react-native-onesignal`

## Android Installation
In your `AndroidManifest.xml`

```xml
.....

<!-- Optional - Add the necessary permissions (Choose one of those) -->

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Approximate location - If you want to use promptLocation for letting OneSignal know the user location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!--  Precise location If you want to use promptLocation for letting OneSignal know the user location. -->

<!-- End optional permissions -->

<application ....>
    <activity
        android:launchMode="singleTop"> <!-- Add this parameter -->
    .....
```

In `android/gradle/wrapper/gradle-wrapper.properties`
````javascript
...

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
```

In `android/settings.gradle`
```gradle
...

include ':react-native-onesignal'
project(':react-native-onesignal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-onesignal/android')
```

In `android/build.gradle`
```gradle
...

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0' // Upgrade gradle

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
```

In `android/app/build.gradle`

```gradle
...

android {
    ...
    buildToolsVersion "23.0.2" // NOT REQUIRED BUT RECOMMENDED - This is good for in-process dex (faster)
    ...
    defaultConfig {
        ...
        manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                                onesignal_app_id: "YOUR_ONESIGNAL_ID",
                                onesignal_google_project_number: "YOUR_GOOGLE_PROJECT_NUMBER"]
    }
}

dependencies {
    ...

    compile project(':react-native-onesignal')
}
```

Register module (in `MainActivity.java`)

```java
import com.geektime.reactnativeonesignal.ReactNativeOneSignalPackage;  // <--- Import

public class MainActivity extends ReactActivity {
  ......

      /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        ...
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new ReactNativeOneSignalPackage(this) // Add this line
        );
    }
  ......

}
```

## iOS Installation

 * Follow the steps according to the official OneSignal SDK Installation here: https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk
 * Make sure you installed the OneSignal Pod.
 * Once you've finished, Open your project in Xcode.

### Importing The Library

 * Drag the file `RCTOneSignal.xcodeproj` from `/node_modules/react-native-onesignal/ios` into the `Libraries` group in the Project navigator. Ensure that `Copy items if needed` is UNCHECKED!

  ![Add Files To...](http://i.imgur.com/puxHiIg.png)

  ![Library Imported Successfuly](http://i.imgur.com/YJPQLPD.png)

 * Ensure that `libRTCOneSignal.a` is linked through `Link Binary With Libraries` on `Build Phases`:

  ![Add Files To...](http://i.imgur.com/IxIQ4s8.png)

 * Ensure that `Header Search Paths` on `Build Settings` has the path `$(SRCROOT)/../node_modules/react-native-onesignal` set to `recursive`:

### Adding the Code
<commit_msg>- Updated Readme with instructions for RN 0.29.<commit_after># React Native OneSignal

React Native Push Notifications support with OneSignal integration.

## Notice Regarding RN 0.29 Support

In RN 0.29 FB changed the way RN libraries should be included in Android, and listen to application life cycle.

Version 1.1.9 would include all features and will support RN version < 0.29, while version 1.2.0 and up will support RN 0.29 and up. New features will be supported only on RN 0.29 and up.

[![npm version](https://img.shields.io/npm/v/react-native-onesignal.svg?style=flat-square)](https://www.npmjs.com/package/react-native-onesignal)
[![npm downloads](https://img.shields.io/npm/dm/react-native-onesignal.svg?style=flat-square)](https://www.npmjs.com/package/react-native-onesignal)

<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->

- [React Native OneSignal](#react-native-onesignal)
	- [Installation](#installation)
	- [Android Installation](#android-installation)
	- [iOS Installation](#ios-installation)
		- [Importing The Library](#importing-the-library)
		- [Adding the Code](#adding-the-code)
	- [Android Usage](#android-usage)
	- [iOS Usage](#ios-usage)
	- [API](#api)
		- [Handling Notifications](#handling-notifications)
		- [Sending and Getting OneSignal Tags](#sending-and-getting-onesignal-tags)
		- [Getting Player ID and Push Token](#getting-player-id-and-push-token)
		- [Enable Vibration](#enable-vibration)
		- [Enable Sound](#enable-sound)
		- [Enable Notification When App Active](#enable-notification-when-app-active)
		- [Enable In-App Alert Notification](#enable-in-app-alert-notification)
		- [Change User Subscription Status](#change-user-subscription-status)
		- [Post Notification (Peer-to-Peer Notifications)](#post-notification-peer-to-peer-notifications)
		- [Prompt Location (Android Only)](#prompt-location-android-only)
		- [Request Push Notification Permissions](#request-push-notification-permissions)
		- [Register For Push Notifications](#register-for-push-notifications)
	- [FAQ / Repeating Issues](#faq-repeating-issues)
		- [Issue 1 - Multiple dex files define:](#issue-1-multiple-dex-files-define)
		- [Issue 2 - Multiple dex files define (Again):](#issue-2-multiple-dex-files-define-again)
	- [CREDITS](#credits)
	- [TODO](#todo)

<!-- /TOC -->

## Installation
`npm install react-native-onesignal`

## Android Installation
In your `AndroidManifest.xml`

```xml
.....

<!-- Optional - Add the necessary permissions (Choose one of those) -->

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Approximate location - If you want to use promptLocation for letting OneSignal know the user location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!--  Precise location If you want to use promptLocation for letting OneSignal know the user location. -->

<!-- End optional permissions -->

<application ....>
    <activity
        android:launchMode="singleTop"> <!-- Add this parameter -->
    .....
```

In `android/gradle/wrapper/gradle-wrapper.properties`
````javascript
...

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
```

In `android/settings.gradle`
```gradle
...

include ':react-native-onesignal'
project(':react-native-onesignal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-onesignal/android')
```

In `android/build.gradle`
```gradle
...

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0' // Upgrade gradle

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
```

In `android/app/build.gradle`

```gradle
...

android {
    ...
    buildToolsVersion "23.0.2" // NOT REQUIRED BUT RECOMMENDED - This is good for in-process dex (faster)
    ...
    defaultConfig {
        ...
        manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                                onesignal_app_id: "YOUR_ONESIGNAL_ID",
                                onesignal_google_project_number: "YOUR_GOOGLE_PROJECT_NUMBER"]
    }
}

dependencies {
    ...

    compile project(':react-native-onesignal')
}
```

### RN < 0.29, Version < 1.2.0

Register module (in `MainActivity.java`)

```java
import com.geektime.reactnativeonesignal.ReactNativeOneSignalPackage;  // <--- Import

public class MainActivity extends ReactActivity {
  ......

      /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        ...
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new ReactNativeOneSignalPackage(this) // Add this line
        );
    }
  ......

}
```

### RN >= 0.29, Version >= 1.2.0

Register module (in `MainApplication.java`)

```java
import com.geektime.reactnativeonesignal.ReactNativeOneSignalPackage;  // <--- Import

public class MainApplication extends Application implements ReactApplication {

	private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
  		......

	      /**
	     * A list of packages used by the app. If the app uses additional views
	     * or modules besides the default ones, add more packages here.
	     */
	    @Override
	    protected List<ReactPackage> getPackages() {
	        ...
	        return Arrays.<ReactPackage>asList(
	                new MainReactPackage(),
	                new ReactNativeOneSignalPackage() // Add this line
	        );
	    }
	};
	......
	@Override
	public ReactNativeHost getReactNativeHost() {
    	return mReactNativeHost;
	}
};

```

## iOS Installation

 * Follow the steps according to the official OneSignal SDK Installation here: https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk
 * Make sure you installed the OneSignal Pod.
 * Once you've finished, Open your project in Xcode.

### Importing The Library

 * Drag the file `RCTOneSignal.xcodeproj` from `/node_modules/react-native-onesignal/ios` into the `Libraries` group in the Project navigator. Ensure that `Copy items if needed` is UNCHECKED!

  ![Add Files To...](http://i.imgur.com/puxHiIg.png)

  ![Library Imported Successfuly](http://i.imgur.com/YJPQLPD.png)

 * Ensure that `libRTCOneSignal.a` is linked through `Link Binary With Libraries` on `Build Phases`:

  ![Add Files To...](http://i.imgur.com/IxIQ4s8.png)

 * Ensure that `Header Search Paths` on `Build Settings` has the path `$(SRCROOT)/../node_modules/react-native-onesignal` set to `recursive`:

### Adding the Code

{'fraction_non_alphanumeric': 0.13591680883906085, 'fraction_numerical': 0.006336826712161832, 'mean_word_length': 3.615673040869891, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, 'https://': 12, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5639128', 'n_tokens_mistral': 3977, 'n_tokens_neox': 3630, 'n_words': 900}