Commit 03065662 authored by Renato Pereira Back's avatar Renato Pereira Back

Merged conflicts.

parents 0da7c56b 77cfdf39
...@@ -96,6 +96,28 @@ If you are using RN < 0.30.0 and react-native-fcm < 1.0.16, pass intent into pac ...@@ -96,6 +96,28 @@ If you are using RN < 0.30.0 and react-native-fcm < 1.0.16, pass intent into pac
+ } + }
``` ```
NOTE: Verify that react-native links correctly in `MainApplication.java`
```diff
import android.app.application
...
+import com.evollu.react.fcm.FIRMessagingPackage;
```
....
```diff
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
+ new FIRMessagingPackage(),
new RNDeviceInfo(),
);
}
```
- RN <= 0.27: - RN <= 0.27:
```diff ```diff
...@@ -125,7 +147,7 @@ Install the `Firebase/Messaging` pod: ...@@ -125,7 +147,7 @@ Install the `Firebase/Messaging` pod:
cd ios && pod init cd ios && pod init
pod install Firebase/Messaging pod install Firebase/Messaging
``` ```
uncomment the "use_framework!" line in the podfile. uncomment the "use_frameworks!" line in the podfile.
### Non Cocoapod approach ### Non Cocoapod approach
...@@ -280,7 +302,7 @@ class App extends Component { ...@@ -280,7 +302,7 @@ class App extends Component {
}); });
FCM.scheduleLocalNotification({ FCM.scheduleLocalNotification({
fire_date: new Date().getTime(), //react convert is used, accept epoch time or ISO string fire_date: new Date().getTime(), //RN's converter is used, accept epoch time and whatever that converter supports
id: "UNIQ_ID_STRING", //REQUIRED! this is what you use to lookup and delete notification. In android notification with same ID will override each other id: "UNIQ_ID_STRING", //REQUIRED! this is what you use to lookup and delete notification. In android notification with same ID will override each other
body: "from future past", body: "from future past",
repeat_interval: "week" //day, hour repeat_interval: "week" //day, hour
...@@ -291,6 +313,10 @@ class App extends Component { ...@@ -291,6 +313,10 @@ class App extends Component {
FCM.cancelAllLocalNotifications(); FCM.cancelAllLocalNotifications();
FCM.setBadgeNumber(); // iOS only and there's no way to set it in Android, yet. FCM.setBadgeNumber(); // iOS only and there's no way to set it in Android, yet.
FCM.getBadgeNumber().then(number=>console.log(number)); // iOS only and there's no way to get it in Android, yet. FCM.getBadgeNumber().then(number=>console.log(number)); // iOS only and there's no way to get it in Android, yet.
FCM.send('984XXXXXXXXX', {
my_custom_data_1: 'my_custom_field_value_1',
my_custom_data_2: 'my_custom_field_value_2'
});
} }
} }
``` ```
...@@ -349,6 +375,18 @@ class App extends Component { ...@@ -349,6 +375,18 @@ class App extends Component {
NOTE: it is recommended 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)). NOTE: it is recommended 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)).
### Quick notes about upstream messages
If your app server implements the [XMPP Connection Server](https://firebase.google.com/docs/cloud-messaging/server#implementing-the-xmpp-connection-server-protocol) protocol, it can receive upstream messages from a user's device to the cloud. To initiate an upstream message, call the `FCM.send()` method with your Firebase `Sender ID` and a `Data Object` as parameters as follows:
```javascript
FCM.send('984XXXXXXXXX', {
my_custom_data_1: 'my_custom_field_value_1',
my_custom_data_2: 'my_custom_field_value_2'
});
```
The `Data Object` is message data comprising as many key-value pairs of the message's payload as are needed (ensure that the value of each pair in the data object is a `string`). Your `Sender ID` is a unique numerical value generated when you created your Firebase project, it is available in the `Cloud Messaging` tab of the Firebase console `Settings` pane. The sender ID is used to identify each app server that can send messages to the client app.
## Q & A ## Q & A
#### Why do you build another local notification #### Why do you build another local notification
......
...@@ -20,6 +20,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; ...@@ -20,6 +20,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.RemoteMessage.Notification;
import android.app.Application; import android.app.Application;
import android.os.Bundle; import android.os.Bundle;
...@@ -174,6 +175,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -174,6 +175,19 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
if (getReactApplicationContext().hasActiveCatalystInstance()) { if (getReactApplicationContext().hasActiveCatalystInstance()) {
RemoteMessage message = intent.getParcelableExtra("data"); RemoteMessage message = intent.getParcelableExtra("data");
WritableMap params = Arguments.createMap(); WritableMap params = Arguments.createMap();
WritableMap fcmData = Arguments.createMap();
if (message.getNotification() != null) {
Notification notification = message.getNotification();
fcmData.putString("title", notification.getTitle());
fcmData.putString("body", notification.getBody());
fcmData.putString("color", notification.getColor());
fcmData.putString("icon", notification.getIcon());
fcmData.putString("tag", notification.getTag());
fcmData.putString("action", notification.getClickAction());
}
params.putMap("fcm", fcmData);
if(message.getData() != null){ if(message.getData() != null){
Map<String, String> data = message.getData(); Map<String, String> data = message.getData();
Set<String> keysIterator = data.keySet(); Set<String> keysIterator = data.keySet();
......
...@@ -100,6 +100,14 @@ RCT_EXPORT_MODULE() ...@@ -100,6 +100,14 @@ RCT_EXPORT_MODULE()
addObserver:self selector:@selector(onTokenRefresh) addObserver:self selector:@selector(onTokenRefresh)
name:kFIRInstanceIDTokenRefreshNotification object:nil]; name:kFIRInstanceIDTokenRefreshNotification object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(sendDataMessageFailure:)
name:FIRMessagingSendErrorNotification object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(sendDataMessageSuccess:)
name:FIRMessagingSendSuccessNotification object:nil];
// For iOS 10 data message (sent via FCM) // For iOS 10 data message (sent via FCM)
[[FIRMessaging messaging] setRemoteMessageDelegate:self]; [[FIRMessaging messaging] setRemoteMessageDelegate:self];
} }
...@@ -274,6 +282,25 @@ RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTP ...@@ -274,6 +282,25 @@ RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTP
resolve(@([RCTSharedApplication() applicationIconBadgeNumber])); resolve(@([RCTSharedApplication() applicationIconBadgeNumber]));
} }
RCT_EXPORT_METHOD(send:(NSString*)senderId withPayload:(NSDictionary *)message)
{
NSMutableDictionary * mMessage = [message mutableCopy];
NSMutableDictionary * upstreamMessage = [[NSMutableDictionary alloc] init];
for (NSString* key in mMessage) {
upstreamMessage[key] = [NSString stringWithFormat:@"%@", [mMessage valueForKey:key]];
}
NSDictionary *imMessage = [NSDictionary dictionaryWithDictionary:upstreamMessage];
int64_t ttl = 3600;
NSString * receiver = [NSString stringWithFormat:@"%@@gcm.googleapis.com", senderId];
NSUUID *uuid = [NSUUID UUID];
NSString * messageID = [uuid UUIDString];
[[FIRMessaging messaging]sendMessage:imMessage to:receiver withMessageID:messageID timeToLive:ttl];
}
- (void)handleNotificationReceived:(NSNotification *)notification - (void)handleNotificationReceived:(NSNotification *)notification
{ {
if([notification.userInfo valueForKey:@"opened_from_tray"] == nil){ if([notification.userInfo valueForKey:@"opened_from_tray"] == nil){
...@@ -286,4 +313,18 @@ RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTP ...@@ -286,4 +313,18 @@ RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTP
} }
- (void)sendDataMessageFailure:(NSNotification *)notification
{
NSString *messageID = (NSString *)notification.userInfo[@"messageID"];
NSLog(@"sendDataMessageFailure: %@", messageID);
}
- (void)sendDataMessageSuccess:(NSNotification *)notification
{
NSString *messageID = (NSString *)notification.userInfo[@"messageID"];
NSLog(@"sendDataMessageSuccess: %@", messageID);
}
@end @end
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
"type": "git", "type": "git",
"url": "git+https://github.com/evollu/react-native-fcm.git" "url": "git+https://github.com/evollu/react-native-fcm.git"
}, },
"version": "2.3.1" "version": "2.3.2"
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment