Skip to content

Commit

Permalink
Merge pull request #1 from renzosal/notifications
Browse files Browse the repository at this point in the history
Notifications
  • Loading branch information
renzosal authored Aug 30, 2016
2 parents 49cf7dc + 2274ee0 commit ed7c308
Show file tree
Hide file tree
Showing 6 changed files with 559 additions and 7 deletions.
68 changes: 65 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
+ <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
+ </intent-filter>
+ </service>

+ <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher" />
...
```

Expand Down Expand Up @@ -131,6 +131,7 @@ Edit `AppDelegate.m`:
```diff
+ #import "Firebase.h" // if you are using Non Cocoapod approach
+ #import "RNFIRMessaging.h"
+ #import "RCTPushNotificationManager.h"
//...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand All @@ -143,6 +144,18 @@ Edit `AppDelegate.m`:
+ [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification];
+ handler(UIBackgroundFetchResultNewData);
+ }

+// Required to register for notifications
+- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
+{
+ [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
+}

+// Required for the localNotification event.
+- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
+{
+ [RCTPushNotificationManager didReceiveLocalNotification:notification];
+}
```

### FCM config file
Expand Down Expand Up @@ -211,15 +224,15 @@ class App extends Component {
```

and event callback will receive as:

- Android
```json
{
"fcm": {"action": "fcm.ACTION.HELLO"},
"extra": "juice"
}
```

- iOS
```json
{
Expand All @@ -233,6 +246,55 @@ class App extends Component {

NOTE: it is recommend not to rely on `data` payload for click_action as it can be overwritten (check [this](http://stackoverflow.com/questions/33738848/handle-multiple-notifications-with-gcm)).


### Local Notifications (still in progress)
Based on react-native-push-notification by zo0r and Neson

```javascript

//support for priority on android
const pushNotification = {
/* Android Only Properties */
id: 0, // (optional) default: Autogenerated Unique ID
priority: "high", //(optional) default: low, other options: 'min', 'max', 'high'
title: "My Notification Title", // (optional)
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
subText: "This is a subText", // (optional) default: none
color: "red", // (optional) default: system default
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: "group", // (optional) add group to message
type:'my_custom_field_value', //custom field
/* iOS and Android properties */
message: "My Notification Message", // (required)
playSound: false, // (optional) default: true
number: 10 // (optional) default: none (Cannot be zero)
};

FCM.presentLocalNotification(pushNotification)

//Schedule Local Notification
PushNotificationIOS will add support for this https://github.com/facebook/react-native/pull/7219 so this will change

const pushNotification = {
//...
repeatEvery: "week"// other options: minute, hour, day, week
//...
}
FCM.scheduleLocalNotification(pushNotification)

//Cancel notifications(IOS and ANDROID)
FCM.cancelAll()

//Android Only
FCM.cancel(notificationId)
```

## Q & A

#### My Android build is failing
Expand Down
Loading

0 comments on commit ed7c308

Please sign in to comment.