Commit 0da7c56b authored by renato's avatar renato

Added Icons and Hybrid Notification

parent bf43c42b
...@@ -47,6 +47,10 @@ export default class App extends Component { ...@@ -47,6 +47,10 @@ export default class App extends Component {
<TouchableOpacity onPress={() => firebaseClient.sendData(token)} style={styles.button}> <TouchableOpacity onPress={() => firebaseClient.sendData(token)} style={styles.button}>
<Text style={styles.buttonText}>Send Data</Text> <Text style={styles.buttonText}>Send Data</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => firebaseClient.sendNotificationWithData(token)} style={styles.button}>
<Text style={styles.buttonText}>Send Notification With Data</Text>
</TouchableOpacity>
</View> </View>
); );
} }
...@@ -73,7 +77,7 @@ const styles = StyleSheet.create({ ...@@ -73,7 +77,7 @@ const styles = StyleSheet.create({
backgroundColor: "teal", backgroundColor: "teal",
paddingHorizontal: 20, paddingHorizontal: 20,
paddingVertical: 10, paddingVertical: 10,
marginVertical: 5, marginVertical: 15,
borderRadius: 10 borderRadius: 10
}, },
buttonText: { buttonText: {
......
...@@ -7,19 +7,18 @@ class FirebaseClient { ...@@ -7,19 +7,18 @@ class FirebaseClient {
constructor() { constructor() {
this.sendData = this.sendData.bind(this); this.sendData = this.sendData.bind(this);
this.sendNotification = this.sendNotification.bind(this); this.sendNotification = this.sendNotification.bind(this);
this.sendNotificationWithData = this.sendNotificationWithData.bind(this);
} }
sendNotification(token) { sendNotification(token) {
let body = { let body = {
"to": token, "to": token,
"notification":{ "notification":{
"icon": "appLogo", "title": "Simple FCM Client",
"title": "Notification Title", "body": "This is a notification with only NOTIFICATION.",
"body": "Notification Body",
"sound": "default", "sound": "default",
"click_action": "fcm.ACTION.HELLO" "click_action": "fcm.ACTION.HELLO"
}, },
"content_available": true,
"priority": 10 "priority": 10
} }
...@@ -30,19 +29,39 @@ class FirebaseClient { ...@@ -30,19 +29,39 @@ class FirebaseClient {
let body = { let body = {
"to": token, "to": token,
"data":{ "data":{
"icon": "appLogo", "title": "Simple FCM Client",
"title": "Notification Title", "body": "This is a notification with only DATA.",
"body": "Notification Body",
"sound": "default", "sound": "default",
"click_action": "fcm.ACTION.HELLO" "click_action": "fcm.ACTION.HELLO",
"remote": true
}, },
"content_available": true, "priority": "normal"
"priority": 10
} }
this._send(JSON.stringify(body), "data"); this._send(JSON.stringify(body), "data");
} }
sendNotificationWithData(token) {
let body = {
"to": token,
"notification":{
"title": "Simple FCM Client",
"body": "This is a notification with NOTIFICATION and DATA (NOTIF).",
"sound": "default",
"click_action": "fcm.ACTION.HELLO"
},
"data":{
"title": "Simple FCM Client",
"body": "This is a notification with NOTIFICATION and DATA (DATA)",
"click_action": "fcm.ACTION.HELLO",
"remote": true
},
"priority": "high"
}
this._send(JSON.stringify(body), "notification-data");
}
_send(body, type) { _send(body, type) {
let headers = new Headers({ let headers = new Headers({
"Content-Type": "application/json", "Content-Type": "application/json",
......
...@@ -23,6 +23,10 @@ export default class PushController extends Component { ...@@ -23,6 +23,10 @@ export default class PushController extends Component {
this.notificationUnsubscribe = FCM.on("notification", notif => { this.notificationUnsubscribe = FCM.on("notification", notif => {
console.log("Notification", notif); console.log("Notification", notif);
if (notif && notif.local) {
return;
}
this.sendRemote(notif);
}); });
this.refreshUnsubscribe = FCM.on("refreshToken", token => { this.refreshUnsubscribe = FCM.on("refreshToken", token => {
...@@ -31,6 +35,17 @@ export default class PushController extends Component { ...@@ -31,6 +35,17 @@ export default class PushController extends Component {
}); });
} }
sendRemote(notif) {
FCM.presentLocalNotification({
title: notif.title,
body: notif.body,
priority: "high",
click_action: notif.click_action,
show_in_foreground: true,
local: true
});
}
componentWillUnmount() { componentWillUnmount() {
this.refreshUnsubscribe(); this.refreshUnsubscribe();
this.notificationUnsubscribe(); this.notificationUnsubscribe();
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
4339BFDD1DAEBA7300F53B62 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFD71DAEBA7300F53B62 /* GoogleUtilities.framework */; }; 4339BFDD1DAEBA7300F53B62 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFD71DAEBA7300F53B62 /* GoogleUtilities.framework */; };
4339BFE01DAEBA7F00F53B62 /* FirebaseMessaging.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFDE1DAEBA7F00F53B62 /* FirebaseMessaging.framework */; }; 4339BFE01DAEBA7F00F53B62 /* FirebaseMessaging.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFDE1DAEBA7F00F53B62 /* FirebaseMessaging.framework */; };
4339BFE11DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFDF1DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework */; }; 4339BFE11DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFDF1DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework */; };
4339BFE51DAED44A00F53B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4339BFE41DAED44A00F53B62 /* GoogleService-Info.plist */; }; 4339BFE81DAEE9D100F53B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
FAE94A218EB64E38BF8D8E9B /* libRNFIRMessaging.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */; }; FAE94A218EB64E38BF8D8E9B /* libRNFIRMessaging.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -152,8 +152,8 @@ ...@@ -152,8 +152,8 @@
4339BFDF1DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = GoogleIPhoneUtilities.framework; sourceTree = "<group>"; }; 4339BFDF1DAEBA7F00F53B62 /* GoogleIPhoneUtilities.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = GoogleIPhoneUtilities.framework; sourceTree = "<group>"; };
4339BFE21DAEBB3500F53B62 /* Firebase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Firebase.h; sourceTree = "<group>"; }; 4339BFE21DAEBB3500F53B62 /* Firebase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Firebase.h; sourceTree = "<group>"; };
4339BFE31DAEBB4800F53B62 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; }; 4339BFE31DAEBB4800F53B62 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
4339BFE41DAED44A00F53B62 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = SimpleFcmClient.entitlements; path = SimpleFcmClient/SimpleFcmClient.entitlements; sourceTree = "<group>"; }; 4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = SimpleFcmClient.entitlements; path = SimpleFcmClient/SimpleFcmClient.entitlements; sourceTree = "<group>"; };
4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNFIRMessaging.a; sourceTree = "<group>"; }; 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNFIRMessaging.a; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
...@@ -274,8 +274,8 @@ ...@@ -274,8 +274,8 @@
13B07FAE1A68108700A75B9A /* SimpleFcmClient */ = { 13B07FAE1A68108700A75B9A /* SimpleFcmClient */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */,
4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */, 4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */,
4339BFE41DAED44A00F53B62 /* GoogleService-Info.plist */,
4339BFE31DAEBB4800F53B62 /* module.modulemap */, 4339BFE31DAEBB4800F53B62 /* module.modulemap */,
4339BFE21DAEBB3500F53B62 /* Firebase.h */, 4339BFE21DAEBB3500F53B62 /* Firebase.h */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */, 008F07F21AC5B25A0029DE68 /* main.jsbundle */,
...@@ -600,9 +600,9 @@ ...@@ -600,9 +600,9 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
4339BFE51DAED44A00F53B62 /* GoogleService-Info.plist in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
4339BFE81DAEE9D100F53B62 /* GoogleService-Info.plist in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
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