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 {
<TouchableOpacity onPress={() => firebaseClient.sendData(token)} style={styles.button}>
<Text style={styles.buttonText}>Send Data</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => firebaseClient.sendNotificationWithData(token)} style={styles.button}>
<Text style={styles.buttonText}>Send Notification With Data</Text>
</TouchableOpacity>
</View>
);
}
......@@ -73,7 +77,7 @@ const styles = StyleSheet.create({
backgroundColor: "teal",
paddingHorizontal: 20,
paddingVertical: 10,
marginVertical: 5,
marginVertical: 15,
borderRadius: 10
},
buttonText: {
......
......@@ -7,19 +7,18 @@ class FirebaseClient {
constructor() {
this.sendData = this.sendData.bind(this);
this.sendNotification = this.sendNotification.bind(this);
this.sendNotificationWithData = this.sendNotificationWithData.bind(this);
}
sendNotification(token) {
let body = {
"to": token,
"notification":{
"icon": "appLogo",
"title": "Notification Title",
"body": "Notification Body",
"notification":{
"title": "Simple FCM Client",
"body": "This is a notification with only NOTIFICATION.",
"sound": "default",
"click_action": "fcm.ACTION.HELLO"
},
"content_available": true,
"priority": 10
}
......@@ -30,19 +29,39 @@ class FirebaseClient {
let body = {
"to": token,
"data":{
"icon": "appLogo",
"title": "Notification Title",
"body": "Notification Body",
"title": "Simple FCM Client",
"body": "This is a notification with only DATA.",
"sound": "default",
"click_action": "fcm.ACTION.HELLO"
"click_action": "fcm.ACTION.HELLO",
"remote": true
},
"content_available": true,
"priority": 10
"priority": "normal"
}
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) {
let headers = new Headers({
"Content-Type": "application/json",
......
......@@ -23,6 +23,10 @@ export default class PushController extends Component {
this.notificationUnsubscribe = FCM.on("notification", notif => {
console.log("Notification", notif);
if (notif && notif.local) {
return;
}
this.sendRemote(notif);
});
this.refreshUnsubscribe = FCM.on("refreshToken", token => {
......@@ -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() {
this.refreshUnsubscribe();
this.notificationUnsubscribe();
......
......@@ -30,7 +30,7 @@
4339BFDD1DAEBA7300F53B62 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFD71DAEBA7300F53B62 /* GoogleUtilities.framework */; };
4339BFE01DAEBA7F00F53B62 /* FirebaseMessaging.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4339BFDE1DAEBA7F00F53B62 /* FirebaseMessaging.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 */; };
FAE94A218EB64E38BF8D8E9B /* libRNFIRMessaging.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */; };
/* End PBXBuildFile section */
......@@ -152,8 +152,8 @@
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>"; };
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>"; };
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>"; };
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>"; };
......@@ -274,8 +274,8 @@
13B07FAE1A68108700A75B9A /* SimpleFcmClient */ = {
isa = PBXGroup;
children = (
4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */,
4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */,
4339BFE41DAED44A00F53B62 /* GoogleService-Info.plist */,
4339BFE31DAEBB4800F53B62 /* module.modulemap */,
4339BFE21DAEBB3500F53B62 /* Firebase.h */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
......@@ -600,9 +600,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4339BFE51DAED44A00F53B62 /* GoogleService-Info.plist in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
4339BFE81DAEE9D100F53B62 /* GoogleService-Info.plist in Resources */,
);
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