Commit 5c200b79 authored by Tolu Olowu's avatar Tolu Olowu Committed by Libin Lu

Make upstream messages work on ios (#151)

In conforming with the method signatures as is the case with the
android version, I limited the arguments for `send()` to just
`senderId` and `payload`. This can still be improved upon by adding
`sendDataMessageSuccess` and `sendDataMessageFailure` to events being
fired across the bridge to Js.
parent 707ce8ff
......@@ -100,6 +100,14 @@ RCT_EXPORT_MODULE()
addObserver:self selector:@selector(onTokenRefresh)
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)
[[FIRMessaging messaging] setRemoteMessageDelegate:self];
}
......@@ -274,6 +282,25 @@ RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTP
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
{
if([notification.userInfo valueForKey:@"opened_from_tray"] == nil){
......@@ -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
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