From 0c53f199d089d4a72d7ae32dad35d8e4e33f7e6d Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Tue, 6 Mar 2018 16:03:50 -0500 Subject: [PATCH] update example --- Examples/simple-fcm-client/app/App.js | 15 +++++--- Examples/simple-fcm-client/app/Listeners.js | 33 ++++++++++-------- Examples/simple-fcm-client/ios/Podfile.lock | 22 ++++++------ .../SimpleFcmClient.xcodeproj/project.pbxproj | 34 +++++++++++++++++-- Examples/simple-fcm-client/package.json | 2 +- Examples/simple-fcm-client/yarn.lock | 6 ++-- 6 files changed, 75 insertions(+), 37 deletions(-) diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index d8cb98a..a6d3170 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -16,7 +16,7 @@ import { import { StackNavigator } from 'react-navigation'; -import FCM from "react-native-fcm"; +import FCM, {NotificationActionType} from "react-native-fcm"; import {registerKilledListener, registerAppListener} from "./Listeners"; import firebaseClient from "./FirebaseClient"; @@ -39,7 +39,7 @@ class MainPage extends Component { this.setState({ initNotif: notif }) - if(notif.targetScreen === 'detail'){ + if(notif && notif.targetScreen === 'detail'){ setTimeout(()=>{ this.props.navigation.navigate('Detail') }, 500) @@ -154,7 +154,14 @@ class MainPage extends Component { body: 'Force touch to reply', priority: "high", show_in_foreground: true, - click_action: "com.myidentifi.fcm.text" + click_action: "com.myidentifi.fcm.text", // for ios + android_actions: JSON.stringify([{ + id: "view", + title: 'view' + },{ + id: "dismiss", + title: 'dismiss' + }]) // for android, take syntax similar to ios's. only buttons are supported }); } @@ -188,7 +195,7 @@ class MainPage extends Component { this.showLocalNotificationWithAction(token)} style={styles.button}> - Show Local Notification with Action (iOS) + 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 4268242..e76186c 100644 --- a/Examples/simple-fcm-client/app/Listeners.js +++ b/Examples/simple-fcm-client/app/Listeners.js @@ -23,19 +23,22 @@ export function registerKilledListener(){ FCM.on(FCMEvent.Notification, notif => { AsyncStorage.setItem('lastNotification', JSON.stringify(notif)); if(notif.opened_from_tray){ - if(notif._actionIdentifier === 'com.myidentifi.fcm.text.reply'){ - if(AppState.currentState !== 'background'){ - alert('User replied '+ JSON.stringify(notif._userText)); - } else { - AsyncStorage.setItem('lastMessage', JSON.stringify(notif._userText)); + setTimeout(()=>{ + if(notif._actionIdentifier === 'reply'){ + if(AppState.currentState !== 'background'){ + console.log('User replied '+ JSON.stringify(notif._userText)) + alert('User replied '+ JSON.stringify(notif._userText)); + } else { + AsyncStorage.setItem('lastMessage', JSON.stringify(notif._userText)); + } } - } - if(notif._actionIdentifier === 'com.myidentifi.fcm.text.view'){ - alert("User clicked View in App"); - } - if(notif._actionIdentifier === 'com.myidentifi.fcm.text.dismiss'){ - alert("User clicked Dismiss"); - } + if(notif._actionIdentifier === 'view'){ + alert("User clicked View in App"); + } + if(notif._actionIdentifier === 'dismiss'){ + alert("User clicked Dismiss"); + } + }, 1000) } }); } @@ -100,7 +103,7 @@ FCM.setNotificationCategories([ actions: [ { type: NotificationActionType.TextInput, - id: 'com.myidentifi.fcm.text.reply', + id: 'reply', title: 'Quick Reply', textInputButtonTitle: 'Send', textInputPlaceholder: 'Say something', @@ -109,14 +112,14 @@ FCM.setNotificationCategories([ }, { type: NotificationActionType.Default, - id: 'com.myidentifi.fcm.text.view', + id: 'view', title: 'View in App', intentIdentifiers: [], options: NotificationActionOption.Foreground }, { type: NotificationActionType.Default, - id: 'com.myidentifi.fcm.text.dismiss', + id: 'dismiss', title: 'Dismiss', intentIdentifiers: [], options: NotificationActionOption.Destructive diff --git a/Examples/simple-fcm-client/ios/Podfile.lock b/Examples/simple-fcm-client/ios/Podfile.lock index cb7e158..dff921b 100644 --- a/Examples/simple-fcm-client/ios/Podfile.lock +++ b/Examples/simple-fcm-client/ios/Podfile.lock @@ -1,20 +1,20 @@ PODS: - - Firebase/Core (4.8.2): + - Firebase/Core (4.9.0): - FirebaseAnalytics (= 4.0.9) - - FirebaseCore (= 4.0.14) - - Firebase/Messaging (4.8.2): + - FirebaseCore (= 4.0.15) + - Firebase/Messaging (4.9.0): - Firebase/Core - - FirebaseMessaging (= 2.0.8) + - FirebaseMessaging (= 2.1.0) - FirebaseAnalytics (4.0.9): - FirebaseCore (~> 4.0) - FirebaseInstanceID (~> 2.0) - GoogleToolboxForMac/NSData+zlib (~> 2.1) - nanopb (~> 0.3) - - FirebaseCore (4.0.14): + - FirebaseCore (4.0.15): - GoogleToolboxForMac/NSData+zlib (~> 2.1) - - FirebaseInstanceID (2.0.8): + - FirebaseInstanceID (2.0.9): - FirebaseCore (~> 4.0) - - FirebaseMessaging (2.0.8): + - FirebaseMessaging (2.1.0): - FirebaseAnalytics (~> 4.0) - FirebaseCore (~> 4.0) - FirebaseInstanceID (~> 2.0) @@ -36,11 +36,11 @@ DEPENDENCIES: - Firebase/Messaging SPEC CHECKSUMS: - Firebase: 7d3b8cd837ad9fcd391657734c0d56dab8e9a5a3 + Firebase: 632216af3ed7f31e3be34776947fdc7546cfb572 FirebaseAnalytics: 388b630c15713f5dbf364071f5f3d6077fb52f4e - FirebaseCore: 2e0b98fb2d64ca8140136beff15772bdd14d2dd7 - FirebaseInstanceID: 81df5805a08001e69138664bdd02c6719a9ac80f - FirebaseMessaging: dfdcd307c2382290a1e297a81d0f18370f5b1bcd + FirebaseCore: 3bd047463058fa6b5d312c97502c52e45401cdfb + FirebaseInstanceID: d2058a35e9bebda1b6dd42486b84917bde552a9d + FirebaseMessaging: 2bafab2d0f3ab3dfd753101c2c32995c2051b5da GoogleToolboxForMac: 2501e2ad72a52eb3dfe7bd9aee7dad11b858bd20 nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03 diff --git a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj index 5f772c8..27945b5 100644 --- a/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj +++ b/Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj @@ -5,6 +5,7 @@ }; objectVersion = 46; objects = { + /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -28,8 +29,8 @@ 5FE70723D2AE04BF2D98342D /* libPods-SimpleFcmClientTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8C044191FA88F1BCCF08BD /* libPods-SimpleFcmClientTests.a */; }; 6976C617E52062E3EE272128 /* libPods-SimpleFcmClient.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A959965489E40CE19F2B06B4 /* libPods-SimpleFcmClient.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; - FAE94A218EB64E38BF8D8E9B /* libRNFIRMessaging.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */; }; B5EEA6C40DAD43C696D4A7EE /* libAirMaps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 441E689027CF4924A5FEA8F6 /* libAirMaps.a */; }; + FAE94A218EB64E38BF8D8E9B /* libRNFIRMessaging.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -201,6 +202,13 @@ remoteGlobalIDString = 2D2A28201D9B03D100D4039D; remoteInfo = "RCTAnimation-tvOS"; }; + 3AA3D5D4204DD40F00C3E8E6 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 955F937AAFAB473EA79C80F7 /* AirMaps.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 11FA5C511C4A1296003AC2EE; + remoteInfo = AirMaps; + }; 3AAE7F501F55B50200E914A8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; @@ -280,17 +288,17 @@ 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 = ""; }; 4339BFE71DAEE9D100F53B62 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 441E689027CF4924A5FEA8F6 /* libAirMaps.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libAirMaps.a; sourceTree = ""; }; 55A6E80F734FA3F596B96C04 /* Pods-SimpleFcmClientTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleFcmClientTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleFcmClientTests/Pods-SimpleFcmClientTests.debug.xcconfig"; sourceTree = ""; }; 64204739CA77D9B1EB1F0788 /* Pods-SimpleFcmClientTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleFcmClientTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleFcmClientTests/Pods-SimpleFcmClientTests.release.xcconfig"; sourceTree = ""; }; 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNFIRMessaging.a; sourceTree = ""; }; 73B4AFC1AC5C6373F8074CBC /* Pods-SimpleFcmClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleFcmClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleFcmClient/Pods-SimpleFcmClient.debug.xcconfig"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; + 955F937AAFAB473EA79C80F7 /* AirMaps.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = AirMaps.xcodeproj; path = "../node_modules/react-native-maps/lib/ios/AirMaps.xcodeproj"; sourceTree = ""; }; A959965489E40CE19F2B06B4 /* libPods-SimpleFcmClient.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SimpleFcmClient.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C7DEB70C413E484CBFA6AC45 /* RNFIRMessaging.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFIRMessaging.xcodeproj; path = "../node_modules/react-native-fcm/ios/RNFIRMessaging.xcodeproj"; sourceTree = ""; }; CF6939675D5A4A68FBE567C0 /* Pods-SimpleFcmClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleFcmClient.release.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleFcmClient/Pods-SimpleFcmClient.release.xcconfig"; sourceTree = ""; }; - 955F937AAFAB473EA79C80F7 /* AirMaps.xcodeproj */ = {isa = PBXFileReference; name = "AirMaps.xcodeproj"; path = "../node_modules/react-native-maps/lib/ios/AirMaps.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; - 441E689027CF4924A5FEA8F6 /* libAirMaps.a */ = {isa = PBXFileReference; name = "libAirMaps.a"; path = "libAirMaps.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -451,10 +459,19 @@ name = Products; sourceTree = ""; }; + 3AA3D5D1204DD40F00C3E8E6 /* Products */ = { + isa = PBXGroup; + children = ( + 3AA3D5D5204DD40F00C3E8E6 /* libAirMaps.a */, + ); + name = Products; + sourceTree = ""; + }; 3AF0A6071F7BE4DC004B899F /* Recovered References */ = { isa = PBXGroup; children = ( 692E216422234A4CB6A7A838 /* libRNFIRMessaging.a */, + 441E689027CF4924A5FEA8F6 /* libAirMaps.a */, ); name = "Recovered References"; sourceTree = ""; @@ -636,6 +653,10 @@ productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; projectDirPath = ""; projectReferences = ( + { + ProductGroup = 3AA3D5D1204DD40F00C3E8E6 /* Products */; + ProjectRef = 955F937AAFAB473EA79C80F7 /* AirMaps.xcodeproj */; + }, { ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */; ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; @@ -855,6 +876,13 @@ remoteRef = 3A7531B320323B0700888478 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 3AA3D5D5204DD40F00C3E8E6 /* libAirMaps.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libAirMaps.a; + remoteRef = 3AA3D5D4204DD40F00C3E8E6 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 3AAE7F511F55B50200E914A8 /* libthird-party.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/Examples/simple-fcm-client/package.json b/Examples/simple-fcm-client/package.json index d96dc56..561d32f 100644 --- a/Examples/simple-fcm-client/package.json +++ b/Examples/simple-fcm-client/package.json @@ -9,7 +9,7 @@ "dependencies": { "react": "16.0.0-alpha.12", "react-native": "^0.47.2", - "react-native-fcm": "^14.0.1", + "react-native-fcm": "^14.1.0", "react-native-maps": "^0.20.1", "react-navigation": "^1.2.1" }, diff --git a/Examples/simple-fcm-client/yarn.lock b/Examples/simple-fcm-client/yarn.lock index 09c90d5..5331a47 100644 --- a/Examples/simple-fcm-client/yarn.lock +++ b/Examples/simple-fcm-client/yarn.lock @@ -3750,9 +3750,9 @@ react-native-drawer-layout@1.3.2: dependencies: react-native-dismiss-keyboard "1.0.0" -react-native-fcm@^14.0.1: - version "14.0.1" - resolved "https://registry.yarnpkg.com/react-native-fcm/-/react-native-fcm-14.0.1.tgz#833e6a38a1b2fd1a9b7b69be35e007f7361fe474" +react-native-fcm@^14.1.0: + version "14.1.0" + resolved "https://registry.yarnpkg.com/react-native-fcm/-/react-native-fcm-14.1.0.tgz#e1b58e041d4cc8bf100206a57bb5182d1324551c" react-native-maps@^0.20.1: version "0.20.1" -- 2.26.2