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
48770b8f
Commit
48770b8f
authored
Jun 09, 2016
by
Libin Lu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11 from gorangajic/master
make lib more user friendly
parents
b53e226f
7a9934ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
39 deletions
+52
-39
README.md
README.md
+24
-26
index.js
index.js
+28
-13
No files found.
README.md
View file @
48770b8f
...
...
@@ -108,32 +108,30 @@ In [firebase console](https://console.firebase.google.com/), you can get `google
## Usage
```
javascript
import
{
DeviceEventEmitter
}
from
'
react-native
'
;
var
FCM
=
require
(
'
react-native-fcm
'
);
componentWillMount
()
{
FCM
.
requestPermissions
();
FCM
.
getFCMToken
().
then
(
data
=>
{
console
.
log
(
data
.
token
)
//store fcm token in your server
});
this
.
fcmNotifLsnr
=
DeviceEventEmitter
.
addListener
(
'
FCMNotificationReceived
'
,
(
notif
)
=>
{
//there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
});
this
.
fcmTokenLsnr
=
DeviceEventEmitter
.
addListener
(
'
FCMTokenRefreshed
'
,
(
data
)
=>
{
console
.
log
(
data
.
token
)
//fcm token may not be available on first load, catch it here
});
}
componentWillUnmount
()
{
//prevent leak
this
.
fcmNotifLsnr
.
remove
();
this
.
fcmTokenLsnr
.
remove
();
}
}
import
FCM
from
'
react-native-fcm
'
;
...
componentWillMount
()
{
FCM
.
requestPermissions
();
FCM
.
getFCMToken
().
then
(
token
=>
{
console
.
log
(
token
)
// store fcm token in your server
});
this
.
notificationUnsubscribe
=
FCM
.
on
(
'
notification
'
,
(
notif
)
=>
{
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
});
this
.
refreshUnsubscribe
=
FCM
.
on
(
'
refresh
'
,
(
data
)
=>
{
console
.
log
(
data
.
token
)
// fcm token may not be available on first load, catch it here
});
}
componentWillUnmount
()
{
// prevent leak
this
.
refreshUnsubscribe
();
this
.
notificationUnsubscribe
();
}
...
```
### Behaviour when sending `notification` and `data` payload through GCM
...
...
index.js
View file @
48770b8f
'
use strict
'
;
import
{
NativeModules
,
DeviceEventEmitter
,
}
from
'
react-native
'
;
var
React
=
require
(
'
react-native
'
);
var
{
NativeModules
}
=
React
;
const
eventsMap
=
{
refersh
:
'
FCMTokenRefreshed
'
,
notification
:
'
FCMNotificationReceived
'
,
};
var
FIRMessaging
=
NativeModules
.
RNFIRMessaging
;
const
FIRMessaging
=
NativeModules
.
RNFIRMessaging
;
c
lass
FCM
{
c
onst
FCM
=
{};
static
getFCMToken
()
{
return
FIRMessaging
.
getFCMToken
();
}
FCM
.
getFCMToken
=
function
getFCMToken
()
{
return
FIRMessaging
.
getFCMToken
();
};
static
requestPermissions
()
{
return
FIRMessaging
.
requestPermissions
();
}
FCM
.
requestPermissions
=
function
requestPermissions
()
{
return
FIRMessaging
.
requestPermissions
();
};
}
FCM
.
on
=
function
on
(
event
,
callback
)
{
const
nativeEvent
=
eventsMap
[
event
];
const
listener
=
DeviceEventEmitter
.
addListener
(
nativeEvent
,
(
params
)
=>
{
callback
(
params
);
});
return
function
remove
()
{
listener
.
remove
();
};
};
FCM
.
initialData
=
FIRMessaging
.
initialData
;
FCM
.
initialAction
=
FIRMessaging
.
initialAction
;
module
.
exports
=
FCM
;
\ No newline at end of file
module
.
exports
=
FCM
;
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