[ios, android] fixed messaging() send() - now a promise on native - added stub method for ios as the existing one was empty

This commit is contained in:
Salakar 2017-03-15 14:00:28 +00:00
parent cd4664fb68
commit 1acbff834f
3 changed files with 7 additions and 22 deletions

View File

@ -165,7 +165,7 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule {
// String senderId, String messageId, String messageType, // String senderId, String messageId, String messageType,
@ReactMethod @ReactMethod
public void send(ReadableMap params, final Callback callback) { public void send(ReadableMap params, final Promise promise) {
ReadableMap data = params.getMap("data"); ReadableMap data = params.getMap("data");
FirebaseMessaging fm = FirebaseMessaging.getInstance(); FirebaseMessaging fm = FirebaseMessaging.getInstance();
RemoteMessage.Builder remoteMessage = new RemoteMessage.Builder(params.getString("sender")); RemoteMessage.Builder remoteMessage = new RemoteMessage.Builder(params.getString("sender"));
@ -194,15 +194,10 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule {
try { try {
fm.send(remoteMessage.build()); fm.send(remoteMessage.build());
WritableMap res = Arguments.createMap(); WritableMap res = Arguments.createMap();
res.putString("status", "success"); promise.resolve(null);
Log.d(TAG, "send: Message sent");
callback.invoke(null, res);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "send: error sending message", e); Log.e(TAG, "send: error sending message", e);
WritableMap error = Arguments.createMap(); promise.reject("messaging/unknown", e.getMessage(), e);
error.putString("code", e.toString());
error.putString("message", e.toString());
callback.invoke(error);
} }
} }

View File

@ -217,20 +217,10 @@ RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userI
} }
} }
RCT_EXPORT_METHOD(sendRemote:(UILocalNotification *)notification
callback:(RCTResponseSenderBlock) callback)
{
}
RCT_EXPORT_METHOD(send:(NSDictionary *) message resolver:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject){
RCT_EXPORT_METHOD(send:(NSString *) senderId // todo
messageId:(NSString *) messageId resolve([NSNull null]);
messageType:(NSString *) messageType
msg: (NSString *) msg
callback:(RCTResponseSenderBlock)callback)
{
} }
RCT_EXPORT_METHOD(listenForTokenRefresh:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(listenForTokenRefresh:(RCTResponseSenderBlock)callback)

View File

@ -49,7 +49,7 @@ export default class Messaging extends Base {
send(remoteMessage: RemoteMessage) { send(remoteMessage: RemoteMessage) {
if (!remoteMessage || !remoteMessage.data) return Promise.reject(new Error('Invalid remote message format provided.')); if (!remoteMessage || !remoteMessage.data) return Promise.reject(new Error('Invalid remote message format provided.'));
return promisify('send', FirebaseMessaging)(remoteMessage); return FirebaseMessaging.send(remoteMessage);
} }
// //