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
bf43c42b
Commit
bf43c42b
authored
Oct 12, 2016
by
renato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added token to state controll instead of constants
parent
58694566
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
Examples/simple-fcm-client/app/App.js
Examples/simple-fcm-client/app/App.js
+19
-3
Examples/simple-fcm-client/app/FirebaseClient.js
Examples/simple-fcm-client/app/FirebaseClient.js
+11
-4
Examples/simple-fcm-client/app/PushController.js
Examples/simple-fcm-client/app/PushController.js
+8
-0
No files found.
Examples/simple-fcm-client/app/App.js
View file @
bf43c42b
...
...
@@ -16,19 +16,35 @@ import PushController from "./PushController";
import
firebaseClient
from
"
./FirebaseClient
"
;
export
default
class
App
extends
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
token
:
""
}
}
render
()
{
let
{
token
}
=
this
.
state
;
return
(
<
View
style
=
{
styles
.
container
}
>
<
PushController
/>
<
PushController
onChangeToken
=
{
token
=>
this
.
setState
({
token
:
token
||
""
})}
/
>
<
Text
style
=
{
styles
.
welcome
}
>
Welcome
to
Simple
Fcm
Client
!
<
/Text
>
<
TouchableOpacity
onPress
=
{()
=>
firebaseClient
.
sendNotification
()}
style
=
{
styles
.
button
}
>
<
Text
style
=
{
styles
.
instructions
}
>
Token
:
{
this
.
state
.
token
}
<
/Text
>
<
TouchableOpacity
onPress
=
{()
=>
firebaseClient
.
sendNotification
(
token
)}
style
=
{
styles
.
button
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Send
Notification
<
/Text
>
<
/TouchableOpacity
>
<
TouchableOpacity
onPress
=
{()
=>
firebaseClient
.
sendData
()}
style
=
{
styles
.
button
}
>
<
TouchableOpacity
onPress
=
{()
=>
firebaseClient
.
sendData
(
token
)}
style
=
{
styles
.
button
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Send
Data
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
...
...
Examples/simple-fcm-client/app/FirebaseClient.js
View file @
bf43c42b
...
...
@@ -4,9 +4,14 @@ const API_URL = "https://fcm.googleapis.com/fcm/send";
class
FirebaseClient
{
sendNotification
()
{
constructor
()
{
this
.
sendData
=
this
.
sendData
.
bind
(
this
);
this
.
sendNotification
=
this
.
sendNotification
.
bind
(
this
);
}
sendNotification
(
token
)
{
let
body
=
{
"
to
"
:
FirebaseConstants
.
TO
,
"
to
"
:
token
,
"
notification
"
:{
"
icon
"
:
"
appLogo
"
,
"
title
"
:
"
Notification Title
"
,
...
...
@@ -14,15 +19,16 @@ class FirebaseClient {
"
sound
"
:
"
default
"
,
"
click_action
"
:
"
fcm.ACTION.HELLO
"
},
"
content_available
"
:
true
,
"
priority
"
:
10
}
this
.
_send
(
JSON
.
stringify
(
body
),
"
notification
"
);
}
sendData
()
{
sendData
(
token
)
{
let
body
=
{
"
to
"
:
FirebaseConstants
.
TO
,
"
to
"
:
token
,
"
data
"
:{
"
icon
"
:
"
appLogo
"
,
"
title
"
:
"
Notification Title
"
,
...
...
@@ -30,6 +36,7 @@ class FirebaseClient {
"
sound
"
:
"
default
"
,
"
click_action
"
:
"
fcm.ACTION.HELLO
"
},
"
content_available
"
:
true
,
"
priority
"
:
10
}
...
...
Examples/simple-fcm-client/app/PushController.js
View file @
bf43c42b
...
...
@@ -2,12 +2,19 @@ import React, { Component } from "react";
import
FCM
from
"
react-native-fcm
"
;
import
firebaseClient
from
"
./FirebaseClient
"
;
export
default
class
PushController
extends
Component
{
constructor
(
props
)
{
super
(
props
);
}
componentDidMount
()
{
FCM
.
requestPermissions
();
FCM
.
getFCMToken
().
then
(
token
=>
{
console
.
log
(
"
TOKEN (getFCMToken)
"
,
token
);
this
.
props
.
onChangeToken
(
token
);
});
FCM
.
getInitialNotification
().
then
(
notif
=>
{
...
...
@@ -20,6 +27,7 @@ export default class PushController extends Component {
this
.
refreshUnsubscribe
=
FCM
.
on
(
"
refreshToken
"
,
token
=>
{
console
.
log
(
"
TOKEN (refreshUnsubscribe)
"
,
token
);
this
.
props
.
onChangeToken
(
token
);
});
}
...
...
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