Skip to content

Commit 8d99a35

Browse files
committed
Merge branch 'upstream-master'
* upstream-master: (89 commits) Split out the JS delivery functionality, so it can be used by ListenerService as well as the RNPushNotification base code (ie the Activity and JS library). fixed scheduleLocalNotification to work on iOS Fixed typo in README.md Allow popInitialNotification to be set on secondary calls to configure(). Start the JS thread to handle any incoming remote notifications we receive on the background listener service. Update README.md Update package.json docs docs docs docs ok, i think / hope we have feature parity with the cancel methods between iOS and Android. You can now specify a dictionary that describes which notifications you want to cancel. See https://github.com/facebook/react-native/blob/master/Libraries/PushNotificationIOS/RCTPushNotificationManager.m#L294 updated again to behave a bit more like iOS - still not quite right though. cancelLocalNotifications has different behaviour docs - fix typo docs attempt to make the interface for the 2 cancel methods agree with the RN iOS docs updated docs fixed PR zo0r#172 Undo remote Activity change from onActivityResult method Removing the activity parameter from onActivityResult as it requires react-native >= 0.33 ... # Conflicts: # android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
2 parents 495af63 + 9c79c13 commit 8d99a35

20 files changed

+1377
-388
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ project.xcworkspace
2727
.idea
2828
.gradle
2929
local.properties
30+
*.iml
3031

3132
# node.js
3233
#
3334
node_modules/*
3435
npm-debug.log
36+
37+
android/android.iml
38+
android/gradle.properties
39+
android/gradle/
40+
android/gradlew
41+
android/gradlew.bat
42+
android/src/main/gen

README.md

Lines changed: 105 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# React Native Push Notifications
2-
[![npm version](https://badge.fury.io/js/react-native-push-notification.svg)](http://badge.fury.io/js/react-native-push-notification)
3-
[![npm downloads](https://img.shields.io/npm/dm/react-native-push-notification.svg?maxAge=2592000)](https://img.shields.io/npm/dm/react-native-push-notification.svg?maxAge=2592000)
2+
[![npm version](https://badge.fury.io/js/react-native-push-notification.svg?update=5)](http://badge.fury.io/js/react-native-push-notification)
3+
[![npm downloads](https://img.shields.io/npm/dm/react-native-push-notification.svg?update=5)](http://badge.fury.io/js/react-native-push-notification)
44

55
React Native Local and Remote Notifications for iOS and Android
66

7+
## Supported React Native Versions
8+
| Component Version | RN Versions | README |
9+
|-----------------------|---------------|------------|
10+
| **1.0.7** | **<= 0.27** | [Open](https://github.com/zo0r/react-native-push-notification/blob/f42723817f1687e0da23e6753eb8a9f0385b6ac5/README.md) |
11+
| **1.0.8** | **0.28** | [Open](https://github.com/zo0r/react-native-push-notification/blob/2eafd1961273ca6a82ad4dd6514fbf1d1a829089/README.md) |
12+
| **2.0.1** | **0.29** | [Open](https://github.com/zo0r/react-native-push-notification/blob/c7ab7cd84ea19e42047379aefaf568bb16a81936/README.md) |
13+
| **2.0.2** | **0.30, 0.31, 0.32** | [Open](https://github.com/zo0r/react-native-push-notification/blob/a0f7d44e904ba0b92933518e5bf6b444f1c90abb/README.md) |
14+
| **>= 2.1.0** | **>= 0.33** | [Open](https://github.com/zo0r/react-native-push-notification/blob/a359e5c00954aa324136eaa9808333d6ca246171/README.md) |
15+
16+
717
## Installation
818
`npm install react-native-push-notification`
919

@@ -21,6 +31,7 @@ The component uses PushNotificationIOS for the iOS part.
2131
dependencies {
2232
...
2333
34+
compile project(':react-native-push-notification')
2435
compile ('com.google.android.gms:play-services-gcm:8.1.0') {
2536
force = true;
2637
}
@@ -30,13 +41,13 @@ dependencies {
3041
In your `AndroidManifest.xml`
3142
```xml
3243
.....
33-
3444
<uses-permission android:name="android.permission.WAKE_LOCK" />
3545
<permission
3646
android:name="${applicationId}.permission.C2D_MESSAGE"
3747
android:protectionLevel="signature" />
3848
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
3949
<uses-permission android:name="android.permission.VIBRATE" />
50+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
4051

4152
<application ....>
4253
<receiver
@@ -48,8 +59,13 @@ In your `AndroidManifest.xml`
4859
<category android:name="${applicationId}" />
4960
</intent-filter>
5061
</receiver>
51-
52-
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
62+
63+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
64+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
65+
<intent-filter>
66+
<action android:name="android.intent.action.BOOT_COMPLETED" />
67+
</intent-filter>
68+
</receiver>
5369
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
5470
<service
5571
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
@@ -58,8 +74,7 @@ In your `AndroidManifest.xml`
5874
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
5975
</intent-filter>
6076
</service>
61-
62-
.....
77+
.....
6378

6479
```
6580

@@ -71,70 +86,30 @@ include ':react-native-push-notification'
7186
project(':react-native-push-notification').projectDir = file('../node_modules/react-native-push-notification/android')
7287
```
7388

74-
In `android/app/build.gradle`
75-
76-
```gradle
77-
...
78-
79-
dependencies {
80-
...
81-
82-
compile project(':react-native-push-notification')
83-
}
84-
```
85-
86-
Register module (in `MainActivity.java`)
89+
Register module (in `MainApplication.java`)
8790

8891
```java
89-
import android.content.Intent; // <--- Import Intent
9092
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage; // <--- Import Package
9193

92-
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
93-
94-
private ReactNativePushNotificationPackage mReactNativePushNotificationPackage; // <------ Add Package Variable
94+
public class MainApplication extends Application implements ReactApplication {
9595

96-
/**
97-
* Returns the name of the main component registered from JavaScript.
98-
* This is used to schedule rendering of the component.
99-
*/
100-
@Override
101-
protected String getMainComponentName() {
102-
return "YOUR_APP_NAME";
103-
}
104-
105-
/**
106-
* Returns whether dev mode should be enabled.
107-
* This enables e.g. the dev menu.
108-
*/
109-
@Override
110-
protected boolean getUseDeveloperSupport() {
96+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
97+
@Override
98+
protected boolean getUseDeveloperSupport() {
11199
return BuildConfig.DEBUG;
112-
}
100+
}
101+
102+
@Override
103+
protected List<ReactPackage> getPackages() {
113104

114-
/**
115-
* A list of packages used by the app. If the app uses additional views
116-
* or modules besides the default ones, add more packages here.
117-
*/
118-
@Override
119-
protected List<ReactPackage> getPackages() {
120-
mReactNativePushNotificationPackage = new ReactNativePushNotificationPackage(this); // <------ Initialize the Package
121105
return Arrays.<ReactPackage>asList(
122-
new MainReactPackage(),
123-
new VectorIconsPackage(),
124-
new FabricPackage(),
125-
mReactNativePushNotificationPackage // <---- Add the Package
106+
new MainReactPackage(),
107+
new ReactNativePushNotificationPackage() // <---- Add the Package
126108
);
127109
}
110+
};
128111

129-
// Add onNewIntent
130-
@Override
131-
protected void onNewIntent (Intent intent) {
132-
super.onNewIntent(intent);
133-
134-
mReactNativePushNotificationPackage.newIntent(intent);
135-
}
136-
137-
....
112+
....
138113
}
139114
```
140115

@@ -154,7 +129,7 @@ PushNotification.configure({
154129
console.log( 'NOTIFICATION:', notification );
155130
},
156131

157-
// ANDROID ONLY: (optional) GCM Sender ID.
132+
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
158133
senderID: "YOUR GCM SENDER ID",
159134

160135
// IOS ONLY (optional): default: all - Permissions to register.
@@ -169,8 +144,8 @@ PushNotification.configure({
169144
popInitialNotification: true,
170145

171146
/**
172-
* IOS ONLY: (optional) default: true
173-
* - Specified if permissions will requested or not,
147+
* (optional) default: true
148+
* - Specified if permissions (ios) and token (android and ios) will requested or not,
174149
* - if not, you must call PushNotificationsHandler.requestPermissions() later
175150
*/
176151
requestPermissions: true,
@@ -184,54 +159,104 @@ Notification object example:
184159
```javascript
185160
{
186161
foreground: false, // BOOLEAN: If the notification was received in foreground or not
162+
userInteraction: false, // BOOLEAN: If the notification was opened by the user from the notification area or not
187163
message: 'My Notification Message', // STRING: The notification message
188164
data: {}, // OBJECT: The push data
189165
}
190166
```
191167

192-
## Local and Schedule Notifications
168+
## Local Notifications
193169
`PushNotification.localNotification(details: Object)`
194170

195-
`PushNotification.localNotificationSchedule(details: Object)`
196-
197171
EXAMPLE:
198172
```javascript
199173
PushNotification.localNotification({
200174
/* Android Only Properties */
201-
id: 0, // (optional) default: Autogenerated Unique ID
202-
title: "My Notification Title", // (optional)
175+
id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
203176
ticker: "My Notification Ticker", // (optional)
204-
autoCancel: true, (optional) default: true
177+
autoCancel: true, // (optional) default: true
205178
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
206179
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
207180
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
208181
subText: "This is a subText", // (optional) default: none
209-
number: 10, // (optional) default: none (Cannot be zero)
210182
color: "red", // (optional) default: system default
183+
vibrate: true, // (optional) default: true
184+
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
185+
tag: 'some_tag', // (optional) add tag to message
186+
group: "group", // (optional) add group to message
187+
ongoing: false, // (optional) set whether this is an "ongoing" notification
188+
189+
/* iOS only properties */
190+
alertAction: // (optional) default: view
191+
category: // (optional) default: null
192+
userInfo: // (optional) default: null (object containing additional notification data)
211193

212194
/* iOS and Android properties */
213-
message: "My Notification Message" // (required)
195+
title: "My Notification Title", // (optional, for iOS this is only used in apple watch, the title will be the app name on other iOS devices)
196+
message: "My Notification Message", // (required)
197+
playSound: false, // (optional) default: true
198+
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
199+
number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
214200
});
201+
```
215202

203+
## Scheduled Notifications
204+
`PushNotification.localNotificationSchedule(details: Object)`
205+
206+
EXAMPLE:
207+
```javascript
216208
PushNotification.localNotificationSchedule({
217-
message: "My Notification Message", // (required)
218-
date: new Date(Date.now() + (60 * 1000)) // in 60 secs
209+
message: "My Notification Message", // (required)
210+
date: new Date(Date.now() + (60 * 1000)) // in 60 secs
219211
});
220212
```
221213

214+
## Custom sounds
215+
216+
In android, add your custom sound file to `[project_root]/android/app/src/main/res/raw`
217+
218+
In iOS, add your custom sound file to the project `Resources` in xCode.
219+
220+
In the location notification json specify the full file name:
221+
222+
soundName: 'my_sound.mp3'
223+
224+
## Cancelling notifications
225+
226+
### 1) cancelLocalNotifications
227+
228+
`PushNotification.cancelLocalNotifications(details);`
229+
230+
The the `details` parameter allows you to specify a `userInfo` dictionary that can be used to match one or more *scheduled* notifications. Each
231+
matched notification is cancelled and its alerts removed from the notification centre. The RN docs suggest this is an optional parameter, but
232+
it is not.
233+
234+
```javascript
235+
PushNotification.cancelLocalNotifications({id: '123'});
236+
```
237+
238+
### 2) cancelAllLocalNotifications
239+
240+
`PushNotification.cancelAllLocalNotifications()`
241+
242+
Cancels all scheduled notifications AND clears the notifications alerts that are in the notification centre.
243+
244+
*NOTE: there is currently no api for removing specific notification alerts from the notification centre.*
245+
246+
## Set application badge icon
247+
248+
`PushNotification.setApplicationIconBadgeNumber(number: number)`
249+
250+
Works natively in iOS.
251+
252+
Uses the [ShortcutBadger](https://github.com/leolin310148/ShortcutBadger) on Android, and as such with not work on all Android devices.
253+
222254
## Sending Notification Data From Server
223255
Same parameters as `PushNotification.localNotification()`
224256

225257
## iOS Only Methods
226258
`PushNotification.checkPermissions(callback: Function)` Check permissions
227259

228-
`PushNotification.setApplicationIconBadgeNumber(number: number)` set badge number
229-
230260
`PushNotification.getApplicationIconBadgeNumber(callback: Function)` get badge number
231261

232262
`PushNotification.abandonPermissions()` Abandon permissions
233-
234-
### TODO
235-
- [X] Add `PushNotification.localNotificationSchedule()` Android support
236-
- [ ] Restore Android local notifications after reboot
237-
File renamed without changes.

android/build.gradle

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:2.1.3'
7+
}
8+
}
9+
10+
allprojects {
11+
repositories {
12+
jcenter()
13+
}
14+
}
15+
116
apply plugin: 'com.android.library'
217

318
android {
@@ -25,6 +40,7 @@ dependencies {
2540
compile fileTree(dir: 'libs', include: ['*.jar'])
2641
testCompile 'junit:junit:4.12'
2742
compile 'com.android.support:appcompat-v7:23.1.1'
28-
compile 'com.facebook.react:react-native:0.16.+'
29-
compile 'com.google.android.gms:play-services-gcm:7.8.0'
43+
compile 'com.facebook.react:react-native:+'
44+
compile 'com.google.android.gms:play-services-gcm:+'
45+
compile 'me.leolin:ShortcutBadger:1.1.8@aar'
3046
}

0 commit comments

Comments
 (0)