react-native-onesignal
Advanced tools
Comparing version 1.1.8 to 1.1.9
34
index.js
@@ -20,2 +20,3 @@ /** | ||
var DEVICE_NOTIF_REG_EVENT = 'remoteNotificationsRegistered'; | ||
var DEVICE_IDS_AVAILABLE = 'idsAvailable'; | ||
@@ -41,6 +42,22 @@ /** | ||
} | ||
if( typeof options.onNotificationsRegistered !== 'undefined' ) { | ||
this.onNotificationsRegistered = options.onNotificationsRegistered; | ||
} | ||
if( typeof options.onIdsAvailable !== 'undefined' ) { | ||
this.onIdsAvailable = options.onIdsAvailable; | ||
} | ||
function handleConnectionStateChange(isConnected) { | ||
if(!isConnected) return; | ||
RNOneSignal.configure(); | ||
NetInfo.isConnected.removeEventListener('change', handleConnectionStateChange); | ||
} | ||
NetInfo.isConnected.fetch().then(isConnected => { | ||
if(isConnected) return RNOneSignal.configure(); | ||
NetInfo.isConnected.addEventListener('change', handleConnectionStateChange); | ||
}); | ||
}; | ||
@@ -156,10 +173,3 @@ | ||
Notifications.idsAvailable = function(idsAvailable) { | ||
NetInfo.isConnected.fetch().then(isConnected => { | ||
if (isConnected == true) { | ||
RNOneSignal.idsAvailable(idsAvailable); | ||
} | ||
else { | ||
return; | ||
} | ||
}); | ||
console.log('Please use the onIdsAvailable event instead, it can be defined in the register options'); | ||
}; | ||
@@ -178,2 +188,8 @@ | ||
DeviceEventEmitter.addListener(DEVICE_IDS_AVAILABLE, function(idsAvailable) { | ||
if (Notifications.onIdsAvailable) { | ||
Notifications.onIdsAvailable(idsAvailable); | ||
} | ||
}); | ||
module.exports = Notifications; |
{ | ||
"name": "react-native-onesignal", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "React Native OneSignal Component", | ||
@@ -5,0 +5,0 @@ "main": "index", |
238
README.md
@@ -5,6 +5,36 @@ # React Native OneSignal | ||
[![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 | ||
@@ -32,2 +62,13 @@ `npm install react-native-onesignal` | ||
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` | ||
@@ -41,2 +82,14 @@ ```gradle | ||
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` | ||
@@ -49,2 +102,4 @@ | ||
... | ||
buildToolsVersion "23.0.2" // NOT REQUIRED BUT RECOMMENDED - This is good for in-process dex (faster) | ||
... | ||
defaultConfig { | ||
@@ -65,2 +120,4 @@ ... | ||
### RN < 0.29 | ||
Register module (in `MainActivity.java`) | ||
@@ -91,2 +148,38 @@ | ||
### RN >= 0.29 | ||
In RN 0.29 FB changed the way RN libraries should be included in Android, and listen to application life cycle. | ||
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 | ||
@@ -167,2 +260,6 @@ | ||
OneSignal.configure({ | ||
onIdsAvailable: function(device) { | ||
console.log('UserId = ', device.userId); | ||
console.log('PushToken = ', device.pushToken); | ||
}, | ||
onNotificationOpened: function(message, data, isActive) { | ||
@@ -206,16 +303,22 @@ console.log('MESSAGE: ', message); | ||
OneSignal.configure({ | ||
onNotificationOpened: function(message, data, isActive) { | ||
var notification = {message: message, data: data, isActive: isActive}; | ||
console.log('NOTIFICATION OPENED: ', notification); | ||
//if (!_navigator) { // Check if there is a navigator object. If not, waiting with the notification. | ||
// console.log('Navigator is null, adding notification to pending list...'); | ||
pendingNotifications.push(notification); | ||
// return; | ||
// } | ||
handleNotification(notification); | ||
} | ||
onIdsAvailable: function(device) { | ||
console.log('UserId = ', device.userId); | ||
console.log('PushToken = ', device.pushToken); | ||
}, | ||
onNotificationOpened: function(message, data, isActive) { | ||
var notification = {message: message, data: data, isActive: isActive}; | ||
console.log('NOTIFICATION OPENED: ', notification); | ||
//if (!_navigator) { // Check if there is a navigator object. If not, waiting with the notification. | ||
// console.log('Navigator is null, adding notification to pending list...'); | ||
pendingNotifications.push(notification); | ||
// return; | ||
// } | ||
handleNotification(notification); | ||
} | ||
}); | ||
``` | ||
## Handling Notifications | ||
## API | ||
### Handling Notifications | ||
When any notification is opened or received the callback `onNotification` is called passing an object with the notification data. | ||
@@ -232,3 +335,3 @@ | ||
## Sending and Getting OneSignal Tags | ||
### Sending and Getting OneSignal Tags | ||
@@ -250,17 +353,18 @@ We exposed the tags API of OneSignal (currently on Android) in order to segment people in a better way. | ||
## Getting Player ID and Push Token | ||
### Getting Player ID and Push Token | ||
We exposed the idsAvailable API of OneSignal (both Android & iOS) as a callback so you can handle it further yourself. | ||
We exposed the idsAvailable API of OneSignal (both Android & iOS) as an event. | ||
Just define a onIdsAvailable callback in the configure options. | ||
*Lets you retrieve the OneSignal user id and push token. Your callback block is called after the device is successfully registered with OneSignal. pushToken will be nil if the user did not accept push notifications.* | ||
````javascript | ||
// Getting idsAvailable | ||
OneSignal.idsAvailable((idsAvailable) => { | ||
console.log(idsAvailable.pushToken); | ||
console.log(idsAvailable.userId); | ||
OneSignal.configure({ | ||
onIdsAvailable: function(device) { | ||
console.log('UserId = ', device.userId); | ||
console.log('PushToken = ', device.pushToken); | ||
} | ||
}); | ||
```` | ||
## Enable Vibration | ||
### Enable Vibration | ||
@@ -276,3 +380,3 @@ We exposed the enableVibrate API of OneSignal (Android only). | ||
## Enable Sound | ||
### Enable Sound | ||
@@ -288,3 +392,3 @@ We exposed the enableSound API of OneSignal (Android only). | ||
## Enable Notification When App Active | ||
### Enable Notification When App Active | ||
@@ -300,3 +404,3 @@ We exposed the enableNotificationsWhenActive API of OneSignal (Android only). | ||
## Enable In-App Alert Notification | ||
### Enable In-App Alert Notification | ||
@@ -312,3 +416,3 @@ We exposed the enableInAppAlertNotification API of OneSignal (both Android & iOS). | ||
## Change User Subscription Status | ||
### Change User Subscription Status | ||
@@ -324,4 +428,25 @@ We exposed the setSubscription API of OneSignal (both Android & iOS). | ||
## Prompt Location (Android Only) | ||
### Post Notification (Peer-to-Peer Notifications) | ||
We exposed the postNotification API of OneSignal, currently supports one Player ID to send a notification to. | ||
We call it internally P2P Notification, and therefore there is a special attribute to listen to while receiving the notification. | ||
*Allows you to send notifications from user to user or schedule ones in the future to be delivered to the current device.* | ||
````javascript | ||
// Calling postNotification | ||
OneSignal.postNotification(contents, data, player_id); | ||
// Listening to postNotification using OneSignal.Configure: | ||
onNotificationOpened: function(message, data, isActive) { | ||
if (data.p2p_notification) { | ||
for (var num in data.p2p_notification) { | ||
// console.log(data.p2p_notification[num]); | ||
} | ||
} | ||
} | ||
```` | ||
### Prompt Location (Android Only) | ||
We exposed the promptLocation API of OneSignal (currently supported only on Android). | ||
@@ -337,3 +462,3 @@ | ||
## Request Push Notification Permissions | ||
### Request Push Notification Permissions | ||
@@ -352,3 +477,3 @@ We exposed the requestPermissions API of OneSignal (currently supported only on iOS). | ||
## Register For Push Notifications | ||
### Register For Push Notifications | ||
@@ -398,7 +523,60 @@ We exposed the registerForPushNotifications API of OneSignal (currently supported only on iOS). | ||
### CREDITS | ||
## FAQ / Repeating Issues | ||
The following issues has been marked as repeating, therefore we decided to devote them a separate section. | ||
### Issue 1 - Multiple dex files define: | ||
```gradle | ||
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzr; | ||
``` | ||
Solution: Update all your Google Play Services dependencies to the latest version rather than to a specific version. | ||
From the Google Play Services documentation: | ||
*Be sure you update this version number each time Google Play services is updated https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project* | ||
In `android/app/build.gradle` | ||
```gradle | ||
... | ||
dependencies { | ||
... | ||
compile "com.google.android.gms:play-services-base:+" | ||
compile "com.google.android.gms:play-services-location:+" | ||
complie "com.google.android.gms:play-services-ads:+" | ||
} | ||
``` | ||
### Issue 2 - Multiple dex files define (Again): | ||
```gradle | ||
:app:dexRelease | ||
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION: | ||
Unknown source file : com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;```` | ||
``` | ||
Solution: Upgrade your gradle to properly handle the dex tasks: | ||
In `android/build.gradle` | ||
```gradle | ||
... | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.1.0' | ||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
``` | ||
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 | ||
```` | ||
## CREDITS | ||
Thanks for all the awesome fellows that contributed to this repository! | ||
@danpe, @lunchieapp, @gaykov, @williamrijksen, @adrienbrault, @kennym, @dunghuynh, @holmesal, @joshuapinter | ||
### TODO | ||
## TODO | ||
* [ ] Tell us? |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3351962
158
565
2