From bdcdcd1f18721df52aac3a8d343f3f8fec1ff771 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Mon, 12 Feb 2018 16:24:00 -0500 Subject: [PATCH] update example with action --- Examples/simple-fcm-client/app/App.js | 31 +++++-------- Examples/simple-fcm-client/app/Listeners.js | 28 +++++++++--- .../SimpleFcmClient.xcodeproj/project.pbxproj | 45 +++++++++++++++++++ 3 files changed, 80 insertions(+), 24 deletions(-) diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index 895acf8..3fcac7a 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -134,21 +134,14 @@ export default class App extends Component { firebaseClient.send(JSON.stringify(body), "data"); } - sendRemoteNotificationWithData(token) { - let body = { - "to": token, - "notification":{ - "title": "Simple FCM Client", - "body": "This is a notification with NOTIFICATION and DATA (NOTIF).", - "sound": "default" - }, - "data":{ - "hello": "there" - }, - "priority": "high" - } - - firebaseClient.send(JSON.stringify(body), "notification-data"); + showLocalNotificationWithAction() { + FCM.presentLocalNotification({ + title: 'Test Notification with action', + body: 'Force touch to reply', + priority: "high", + show_in_foreground: true, + click_action: "com.myidentifi.fcm.text" + }); } render() { @@ -185,12 +178,12 @@ export default class App extends Component { Send Remote Data - this.sendRemoteNotificationWithData(token)} style={styles.button}> - Send Remote Notification With Data + this.showLocalNotification()} style={styles.button}> + Show Local Notification - this.showLocalNotification()} style={styles.button}> - Send Local Notification + this.showLocalNotificationWithAction(token)} style={styles.button}> + Show Local Notification with Action this.scheduleLocalNotification()} style={styles.button}> diff --git a/Examples/simple-fcm-client/app/Listeners.js b/Examples/simple-fcm-client/app/Listeners.js index f576627..866a5bf 100644 --- a/Examples/simple-fcm-client/app/Listeners.js +++ b/Examples/simple-fcm-client/app/Listeners.js @@ -1,6 +1,6 @@ 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=>{ if(data){ @@ -21,11 +21,11 @@ export function registerKilledListener(){ export function registerAppListener(){ FCM.on(FCMEvent.Notification, notif => { console.log("Notification", notif); - if(notif.local_notification){ - return; - } + if(notif.opened_from_tray){ - return; + if(notif._actionIdentifier === 'com.myidentifi.fcm.text.reply'){ + alert("User replied: "+notif._userText); + } } if(Platform.OS ==='ios'){ @@ -61,3 +61,21 @@ export function registerAppListener(){ FCM.isDirectChannelEstablished().then(d => console.log(d)); }, 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] + } +]) diff --git a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj index fa93f26..4065653 100644 --- a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj +++ b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 140ED2AC1D01E1AD002B40FF /* 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 */; }; + 3A7531B520323B2400888478 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A7531B220323B0700888478 /* libRCTAnimation.a */; }; 3AC87E631F6C190900194883 /* bell.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 3AC87E621F6C190900194883 /* bell.mp3 */; }; 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 */; }; @@ -186,6 +187,20 @@ remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4; 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 */ = { isa = PBXContainerItemProxy; containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; @@ -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 = ""; }; 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; }; + 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; 3AC87E621F6C190900194883 /* bell.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = bell.mp3; sourceTree = ""; }; 4339BFE31DAEBB4800F53B62 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; 4339BFE61DAED4D900F53B62 /* SimpleFcmClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = SimpleFcmClient.entitlements; path = SimpleFcmClient/SimpleFcmClient.entitlements; sourceTree = ""; }; @@ -289,6 +305,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 3A7531B520323B2400888478 /* libRCTAnimation.a in Frameworks */, 3A6D62911E2044AB00D0D2C7 /* libz.tbd in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, @@ -422,6 +439,15 @@ name = Products; sourceTree = ""; }; + 3A7531AD20323B0700888478 /* Products */ = { + isa = PBXGroup; + children = ( + 3A7531B220323B0700888478 /* libRCTAnimation.a */, + 3A7531B420323B0700888478 /* libRCTAnimation.a */, + ); + name = Products; + sourceTree = ""; + }; 3AF0A6071F7BE4DC004B899F /* Recovered References */ = { isa = PBXGroup; children = ( @@ -472,6 +498,7 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( + 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, @@ -609,6 +636,10 @@ ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */; ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; }, + { + ProductGroup = 3A7531AD20323B0700888478 /* Products */; + ProjectRef = 3A7531AC20323B0700888478 /* RCTAnimation.xcodeproj */; + }, { ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; @@ -806,6 +837,20 @@ remoteRef = 3A6D627D1E20428000D0D2C7 /* PBXContainerItemProxy */; 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 */ = { isa = PBXReferenceProxy; fileType = archive.ar; -- 2.26.2