diff --git a/Examples/simple-fcm-client/app/FirebaseClient.js b/Examples/simple-fcm-client/app/FirebaseClient.js index b8a85686d3319d2382805dd6785df3a03f9455d0..cd76067bc13b718c5ea37c621593da5eb19668da 100644 --- a/Examples/simple-fcm-client/app/FirebaseClient.js +++ b/Examples/simple-fcm-client/app/FirebaseClient.js @@ -1,5 +1,5 @@ import FirebaseConstants from "./FirebaseConstants"; -import { Platform } from "react-native"; +import { Platform, Alert } from "react-native"; const API_URL = "https://fcm.googleapis.com/fcm/send"; @@ -17,12 +17,11 @@ class FirebaseClient { "notification":{ "title": "Simple FCM Client", "body": "This is a notification with only NOTIFICATION.", - "sound": "default", - "click_action": "fcm.ACTION.HELLO" + "sound": "default" }, "priority": 10 } - + if(Platform.OS === 'android'){ body = { "to": token, @@ -47,9 +46,7 @@ class FirebaseClient { "data":{ "title": "Simple FCM Client", "body": "This is a notification with only DATA.", - "sound": "default", - "click_action": "fcm.ACTION.HELLO", - "remote": true + "sound": "default" }, "priority": "normal" } @@ -63,14 +60,10 @@ class FirebaseClient { "notification":{ "title": "Simple FCM Client", "body": "This is a notification with NOTIFICATION and DATA (NOTIF).", - "sound": "default", - "click_action": "fcm.ACTION.HELLO" + "sound": "default" }, "data":{ - "title": "Simple FCM Client", - "body": "This is a notification with NOTIFICATION and DATA (DATA)", - "click_action": "fcm.ACTION.HELLO", - "remote": true + "hello": "there" }, "priority": "high" } @@ -78,16 +71,25 @@ class FirebaseClient { this._send(JSON.stringify(body), "notification-data"); } - _send(body, type) { + async _send(body, type) { + if(FirebaseClient.KEY === 'YOUR_API_KEY'){ + Alert.alert('Set your API_KEY in app/FirebaseConstants.js') + return; + } let headers = new Headers({ "Content-Type": "application/json", - "Content-Length": parseInt(body.length), "Authorization": "key=" + FirebaseConstants.KEY }); - fetch(API_URL, { method: "POST", headers, body }) - .then(response => console.log("Send " + type + " response", response)) - .catch(error => console.log("Error sending " + type, error)); + try { + let response = await fetch(API_URL, { method: "POST", headers, body }); + response = await response.json(); + if(!response.success){ + Alert.alert('Failed to send notification, check error log') + } + } catch (err) { + Alert.alert(err && err.message) + } } } diff --git a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj index 1386b36f1911ef991d1432256a255965c5516c76..a33a29d6994d9b1d1efc92089b5d468715e9e7dd 100644 --- a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj +++ b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj @@ -422,6 +422,14 @@ name = Products; sourceTree = ""; }; + 3AF0A6071F7BE4DC004B899F /* Recovered References */ = { + isa = PBXGroup; + children = ( + 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */, + ); + name = "Recovered References"; + sourceTree = ""; + }; 4339BFC21DAEBA3900F53B62 /* Products */ = { isa = PBXGroup; children = ( @@ -497,6 +505,7 @@ 00E356EF1AD99517003FC87E /* SimpleFcmClientTests */, 83CBBA001A601CBA00E9B192 /* Products */, 7E63D0154B6803F90ADF7C78 /* Pods */, + 3AF0A6071F7BE4DC004B899F /* Recovered References */, ); indentWidth = 2; sourceTree = ""; diff --git a/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m b/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m index 8a77da2aeae3eafa9a84ff4be2988870c15ab02f..48f3623c3bd677507affa56313841a9283fa6b16 100644 --- a/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m +++ b/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m @@ -45,7 +45,7 @@ [RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler]; } -- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; }