Commit bdcdcd1f authored by Libin Lu's avatar Libin Lu

update example with action

parent 05d33533
...@@ -134,21 +134,14 @@ export default class App extends Component { ...@@ -134,21 +134,14 @@ export default class App extends Component {
firebaseClient.send(JSON.stringify(body), "data"); firebaseClient.send(JSON.stringify(body), "data");
} }
sendRemoteNotificationWithData(token) { showLocalNotificationWithAction() {
let body = { FCM.presentLocalNotification({
"to": token, title: 'Test Notification with action',
"notification":{ body: 'Force touch to reply',
"title": "Simple FCM Client", priority: "high",
"body": "This is a notification with NOTIFICATION and DATA (NOTIF).", show_in_foreground: true,
"sound": "default" click_action: "com.myidentifi.fcm.text"
}, });
"data":{
"hello": "there"
},
"priority": "high"
}
firebaseClient.send(JSON.stringify(body), "notification-data");
} }
render() { render() {
...@@ -185,12 +178,12 @@ export default class App extends Component { ...@@ -185,12 +178,12 @@ export default class App extends Component {
<Text style={styles.buttonText}>Send Remote Data</Text> <Text style={styles.buttonText}>Send Remote Data</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => this.sendRemoteNotificationWithData(token)} style={styles.button}> <TouchableOpacity onPress={() => this.showLocalNotification()} style={styles.button}>
<Text style={styles.buttonText}>Send Remote Notification With Data</Text> <Text style={styles.buttonText}>Show Local Notification</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => this.showLocalNotification()} style={styles.button}> <TouchableOpacity onPress={() => this.showLocalNotificationWithAction(token)} style={styles.button}>
<Text style={styles.buttonText}>Send Local Notification</Text> <Text style={styles.buttonText}>Show Local Notification with Action</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => this.scheduleLocalNotification()} style={styles.button}> <TouchableOpacity onPress={() => this.scheduleLocalNotification()} style={styles.button}>
......
import { Platform, AsyncStorage } from 'react-native'; import { Platform, AsyncStorage } from 'react-native';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from "react-native-fcm"; import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType, NotificationActionType, NotificationActionOption, NotificationCategoryOption} from "react-native-fcm";
AsyncStorage.getItem('lastNotification').then(data=>{ AsyncStorage.getItem('lastNotification').then(data=>{
if(data){ if(data){
...@@ -21,11 +21,11 @@ export function registerKilledListener(){ ...@@ -21,11 +21,11 @@ export function registerKilledListener(){
export function registerAppListener(){ export function registerAppListener(){
FCM.on(FCMEvent.Notification, notif => { FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif); console.log("Notification", notif);
if(notif.local_notification){
return;
}
if(notif.opened_from_tray){ if(notif.opened_from_tray){
return; if(notif._actionIdentifier === 'com.myidentifi.fcm.text.reply'){
alert("User replied: "+notif._userText);
}
} }
if(Platform.OS ==='ios'){ if(Platform.OS ==='ios'){
...@@ -61,3 +61,21 @@ export function registerAppListener(){ ...@@ -61,3 +61,21 @@ export function registerAppListener(){
FCM.isDirectChannelEstablished().then(d => console.log(d)); FCM.isDirectChannelEstablished().then(d => console.log(d));
}, 1000); }, 1000);
} }
FCM.setNotificationCategories([
{
id: 'com.myidentifi.fcm.text',
actions: [
{
type: NotificationActionType.TextInput,
id: 'com.myidentifi.fcm.text.reply',
title: 'Reply',
textInputButtonTitle: 'Send',
textInputPlaceholder: 'Say something',
intentIdentifiers: [],
options: NotificationActionOption.AuthenticationRequired
}
],
options: [NotificationCategoryOption.CustomDismissAction, NotificationCategoryOption.PreviewsShowTitle]
}
])
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
3A6D62911E2044AB00D0D2C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A6D62901E2044AB00D0D2C7 /* libz.tbd */; }; 3A6D62911E2044AB00D0D2C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A6D62901E2044AB00D0D2C7 /* libz.tbd */; };
3A7531B520323B2400888478 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A7531B220323B0700888478 /* libRCTAnimation.a */; };
3AC87E631F6C190900194883 /* bell.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 3AC87E621F6C190900194883 /* bell.mp3 */; }; 3AC87E631F6C190900194883 /* bell.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 3AC87E621F6C190900194883 /* bell.mp3 */; };
4339BFE81DAEE9D100F53B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */; }; 4339BFE81DAEE9D100F53B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */; };
5FE70723D2AE04BF2D98342D /* libPods-SimpleFcmClientTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8C044191FA88F1BCCF08BD /* libPods-SimpleFcmClientTests.a */; }; 5FE70723D2AE04BF2D98342D /* libPods-SimpleFcmClientTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8C044191FA88F1BCCF08BD /* libPods-SimpleFcmClientTests.a */; };
...@@ -186,6 +187,20 @@ ...@@ -186,6 +187,20 @@
remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4; remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4;
remoteInfo = "jschelpers-tvOS"; remoteInfo = "jschelpers-tvOS";
}; };
3A7531B120323B0700888478 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTAnimation;
};
3A7531B320323B0700888478 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 2D2A28201D9B03D100D4039D;
remoteInfo = "RCTAnimation-tvOS";
};
3AAE7F501F55B50200E914A8 /* PBXContainerItemProxy */ = { 3AAE7F501F55B50200E914A8 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
...@@ -260,6 +275,7 @@ ...@@ -260,6 +275,7 @@
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
3A6D628E1E20449400D0D2C7 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; 3A6D628E1E20449400D0D2C7 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
3A6D62901E2044AB00D0D2C7 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 3A6D62901E2044AB00D0D2C7 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
3AC87E621F6C190900194883 /* bell.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = bell.mp3; sourceTree = "<group>"; }; 3AC87E621F6C190900194883 /* bell.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = bell.mp3; 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>"; };
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>"; };
...@@ -289,6 +305,7 @@ ...@@ -289,6 +305,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3A7531B520323B2400888478 /* libRCTAnimation.a in Frameworks */,
3A6D62911E2044AB00D0D2C7 /* libz.tbd in Frameworks */, 3A6D62911E2044AB00D0D2C7 /* libz.tbd in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
...@@ -422,6 +439,15 @@ ...@@ -422,6 +439,15 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
3A7531AD20323B0700888478 /* Products */ = {
isa = PBXGroup;
children = (
3A7531B220323B0700888478 /* libRCTAnimation.a */,
3A7531B420323B0700888478 /* libRCTAnimation.a */,
);
name = Products;
sourceTree = "<group>";
};
3AF0A6071F7BE4DC004B899F /* Recovered References */ = { 3AF0A6071F7BE4DC004B899F /* Recovered References */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -472,6 +498,7 @@ ...@@ -472,6 +498,7 @@
832341AE1AAA6A7D00B99B32 /* Libraries */ = { 832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */,
146833FF1AC3E56700842450 /* React.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */,
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */,
...@@ -609,6 +636,10 @@ ...@@ -609,6 +636,10 @@
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */; ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
}, },
{
ProductGroup = 3A7531AD20323B0700888478 /* Products */;
ProjectRef = 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */;
},
{ {
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
...@@ -806,6 +837,20 @@ ...@@ -806,6 +837,20 @@
remoteRef = 3A6D627D1E20428000D0D2C7 /* PBXContainerItemProxy */; remoteRef = 3A6D627D1E20428000D0D2C7 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
3A7531B220323B0700888478 /* libRCTAnimation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAnimation.a;
remoteRef = 3A7531B120323B0700888478 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
3A7531B420323B0700888478 /* libRCTAnimation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAnimation.a;
remoteRef = 3A7531B320323B0700888478 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
3AAE7F511F55B50200E914A8 /* libthird-party.a */ = { 3AAE7F511F55B50200E914A8 /* libthird-party.a */ = {
isa = PBXReferenceProxy; isa = PBXReferenceProxy;
fileType = archive.ar; fileType = archive.ar;
......
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