Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-fcm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
react-native-fcm
Commits
41970d9a
Commit
41970d9a
authored
Feb 12, 2018
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
2e4230fa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
18 deletions
+53
-18
Examples/simple-fcm-client/app/App.js
Examples/simple-fcm-client/app/App.js
+9
-9
Examples/simple-fcm-client/app/Listeners.js
Examples/simple-fcm-client/app/Listeners.js
+42
-9
Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme
...xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme
+2
-0
No files found.
Examples/simple-fcm-client/app/App.js
View file @
41970d9a
...
...
@@ -153,15 +153,6 @@ export default class App extends Component {
Welcome
to
Simple
Fcm
Client
!
<
/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
}
>
{
this
.
state
.
tokenCopyFeedback
}
<
/Text
>
...
...
@@ -189,6 +180,15 @@ export default class App extends Component {
<TouchableOpacity onPress={() => this.scheduleLocalNotification()} style={styles.button}>
<Text style={styles.buttonText}>Schedule Notification in 5s</Text>
</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>
);
}
...
...
Examples/simple-fcm-client/app/Listeners.js
View file @
41970d9a
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
"
;
...
...
@@ -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
(){
// these callback will be triggered even when app is killed
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
));
}
}
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(){
FCM
.
on
(
FCMEvent
.
Notification
,
notif
=>
{
console
.
log
(
"
Notification
"
,
notif
);
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
'
&&
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
(
Platform
.
OS
===
'
ios
'
){
...
...
@@ -72,17 +97,25 @@ FCM.setNotificationCategories([
{
type
:
NotificationActionType
.
TextInput
,
id
:
'
com.myidentifi.fcm.text.reply
'
,
title
:
'
Reply
'
,
title
:
'
Quick
Reply
'
,
textInputButtonTitle
:
'
Send
'
,
textInputPlaceholder
:
'
Say something
'
,
intentIdentifiers
:
[],
options
:
NotificationActionOption
.
AuthenticationRequired
},
{
type
:
NotificationActionType
.
Default
,
id
:
'
com.myidentifi.fcm.text.view
'
,
title
:
'
View in App
'
,
intentIdentifiers
:
[],
options
:
NotificationActionOption
.
Foreground
},
{
type
:
NotificationActionType
.
Default
,
id
:
'
com.myidentifi.fcm.text.dismiss
'
,
title
:
'
Dismiss
'
,
intentIdentifiers
:
[]
intentIdentifiers
:
[],
options
:
NotificationActionOption
.
Destructive
}
],
options
:
[
NotificationCategoryOption
.
CustomDismissAction
,
NotificationCategoryOption
.
PreviewsShowTitle
]
...
...
Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/xcshareddata/xcschemes/SimpleFcmClient.xcscheme
View file @
41970d9a
...
...
@@ -54,6 +54,7 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
shouldUseLaunchSchemeArgsEnv =
"YES"
>
<Testables>
<TestableReference
...
...
@@ -83,6 +84,7 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
launchStyle =
"0"
useCustomWorkingDirectory =
"NO"
ignoresPersistentStateOnLaunch =
"NO"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment