Commit 41970d9a authored by Libin Lu's avatar Libin Lu

update example

parent 2e4230fa
...@@ -153,15 +153,6 @@ export default class App extends Component { ...@@ -153,15 +153,6 @@ export default class App extends Component {
Welcome to Simple Fcm Client! Welcome to Simple Fcm Client!
</Text> </Text>
<Text>
Init notif: {JSON.stringify(this.state.initNotif)}
</Text>
<Text selectable={true} onPress={() => this.setClipboardContent(this.state.token)} style={styles.instructions}>
Token: {this.state.token}
</Text>
<Text style={styles.feedback}> <Text style={styles.feedback}>
{this.state.tokenCopyFeedback} {this.state.tokenCopyFeedback}
</Text> </Text>
...@@ -189,6 +180,15 @@ export default class App extends Component { ...@@ -189,6 +180,15 @@ export default class App extends Component {
<TouchableOpacity onPress={() => this.scheduleLocalNotification()} style={styles.button}> <TouchableOpacity onPress={() => this.scheduleLocalNotification()} style={styles.button}>
<Text style={styles.buttonText}>Schedule Notification in 5s</Text> <Text style={styles.buttonText}>Schedule Notification in 5s</Text>
</TouchableOpacity> </TouchableOpacity>
<Text>
Init notif: {JSON.stringify(this.state.initNotif)}
</Text>
<Text selectable={true} onPress={() => this.setClipboardContent(this.state.token)} style={styles.instructions}>
Token: {this.state.token}
</Text>
</View> </View>
); );
} }
......
import { Platform, AsyncStorage } from 'react-native'; import { Platform, AsyncStorage, AppState } from 'react-native';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType, NotificationActionType, NotificationActionOption, NotificationCategoryOption} from "react-native-fcm"; import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType, NotificationActionType, NotificationActionOption, NotificationCategoryOption} from "react-native-fcm";
...@@ -10,10 +10,33 @@ AsyncStorage.getItem('lastNotification').then(data=>{ ...@@ -10,10 +10,33 @@ AsyncStorage.getItem('lastNotification').then(data=>{
} }
}) })
AsyncStorage.getItem('lastMessage').then(data=>{
if(data){
// if notification arrives when app is killed, it should still be logged here
console.log('last message', JSON.parse(data));
AsyncStorage.removeItem('lastMessage');
}
})
export function registerKilledListener(){ export function registerKilledListener(){
// these callback will be triggered even when app is killed // these callback will be triggered even when app is killed
FCM.on(FCMEvent.Notification, notif => { FCM.on(FCMEvent.Notification, notif => {
AsyncStorage.setItem('lastNotification', JSON.stringify(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));
}
}
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");
}
}
}); });
} }
...@@ -22,13 +45,15 @@ export function registerAppListener(){ ...@@ -22,13 +45,15 @@ export function registerAppListener(){
FCM.on(FCMEvent.Notification, notif => { FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif); console.log("Notification", notif);
if(Platform.OS ==='ios' && notif._notificationType === NotificationType.WillPresent && !notif.local_notification){
// this notification is only to decide if you want to show the notification when user if in forground.
// usually you can ignore it. just decide to show or not.
notif.finish(WillPresentNotificationResult.All)
return;
}
if(notif.opened_from_tray){ if(notif.opened_from_tray){
if(notif._actionIdentifier === 'com.myidentifi.fcm.text.reply'){
alert("User replied: "+notif._userText);
}
if(notif._actionIdentifier === 'com.myidentifi.fcm.text.dismiss'){
alert("User clicked Dismiss");
}
} }
if(Platform.OS ==='ios'){ if(Platform.OS ==='ios'){
...@@ -72,17 +97,25 @@ FCM.setNotificationCategories([ ...@@ -72,17 +97,25 @@ FCM.setNotificationCategories([
{ {
type: NotificationActionType.TextInput, type: NotificationActionType.TextInput,
id: 'com.myidentifi.fcm.text.reply', id: 'com.myidentifi.fcm.text.reply',
title: 'Reply', title: 'Quick Reply',
textInputButtonTitle: 'Send', textInputButtonTitle: 'Send',
textInputPlaceholder: 'Say something', textInputPlaceholder: 'Say something',
intentIdentifiers: [], intentIdentifiers: [],
options: NotificationActionOption.AuthenticationRequired options: NotificationActionOption.AuthenticationRequired
}, },
{
type: NotificationActionType.Default,
id: 'com.myidentifi.fcm.text.view',
title: 'View in App',
intentIdentifiers: [],
options: NotificationActionOption.Foreground
},
{ {
type: NotificationActionType.Default, type: NotificationActionType.Default,
id: 'com.myidentifi.fcm.text.dismiss', id: 'com.myidentifi.fcm.text.dismiss',
title: 'Dismiss', title: 'Dismiss',
intentIdentifiers: [] intentIdentifiers: [],
options: NotificationActionOption.Destructive
} }
], ],
options: [NotificationCategoryOption.CustomDismissAction, NotificationCategoryOption.PreviewsShowTitle] options: [NotificationCategoryOption.CustomDismissAction, NotificationCategoryOption.PreviewsShowTitle]
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
<TestableReference <TestableReference
...@@ -83,6 +84,7 @@ ...@@ -83,6 +84,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
......
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