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
720709e4
Commit
720709e4
authored
Sep 27, 2017
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
defb0962
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
19 deletions
+30
-19
Examples/simple-fcm-client/app/FirebaseClient.js
Examples/simple-fcm-client/app/FirebaseClient.js
+20
-18
Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj
...-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj
+9
-0
Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m
Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m
+1
-1
No files found.
Examples/simple-fcm-client/app/FirebaseClient.js
View file @
720709e4
import
FirebaseConstants
from
"
./FirebaseConstants
"
;
import
FirebaseConstants
from
"
./FirebaseConstants
"
;
import
{
Platform
}
from
"
react-native
"
;
import
{
Platform
,
Alert
}
from
"
react-native
"
;
const
API_URL
=
"
https://fcm.googleapis.com/fcm/send
"
;
const
API_URL
=
"
https://fcm.googleapis.com/fcm/send
"
;
...
@@ -17,12 +17,11 @@ class FirebaseClient {
...
@@ -17,12 +17,11 @@ class FirebaseClient {
"
notification
"
:{
"
notification
"
:{
"
title
"
:
"
Simple FCM Client
"
,
"
title
"
:
"
Simple FCM Client
"
,
"
body
"
:
"
This is a notification with only NOTIFICATION.
"
,
"
body
"
:
"
This is a notification with only NOTIFICATION.
"
,
"
sound
"
:
"
default
"
,
"
sound
"
:
"
default
"
"
click_action
"
:
"
fcm.ACTION.HELLO
"
},
},
"
priority
"
:
10
"
priority
"
:
10
}
}
if
(
Platform
.
OS
===
'
android
'
){
if
(
Platform
.
OS
===
'
android
'
){
body
=
{
body
=
{
"
to
"
:
token
,
"
to
"
:
token
,
...
@@ -47,9 +46,7 @@ class FirebaseClient {
...
@@ -47,9 +46,7 @@ class FirebaseClient {
"
data
"
:{
"
data
"
:{
"
title
"
:
"
Simple FCM Client
"
,
"
title
"
:
"
Simple FCM Client
"
,
"
body
"
:
"
This is a notification with only DATA.
"
,
"
body
"
:
"
This is a notification with only DATA.
"
,
"
sound
"
:
"
default
"
,
"
sound
"
:
"
default
"
"
click_action
"
:
"
fcm.ACTION.HELLO
"
,
"
remote
"
:
true
},
},
"
priority
"
:
"
normal
"
"
priority
"
:
"
normal
"
}
}
...
@@ -63,14 +60,10 @@ class FirebaseClient {
...
@@ -63,14 +60,10 @@ class FirebaseClient {
"
notification
"
:{
"
notification
"
:{
"
title
"
:
"
Simple FCM Client
"
,
"
title
"
:
"
Simple FCM Client
"
,
"
body
"
:
"
This is a notification with NOTIFICATION and DATA (NOTIF).
"
,
"
body
"
:
"
This is a notification with NOTIFICATION and DATA (NOTIF).
"
,
"
sound
"
:
"
default
"
,
"
sound
"
:
"
default
"
"
click_action
"
:
"
fcm.ACTION.HELLO
"
},
},
"
data
"
:{
"
data
"
:{
"
title
"
:
"
Simple FCM Client
"
,
"
hello
"
:
"
there
"
"
body
"
:
"
This is a notification with NOTIFICATION and DATA (DATA)
"
,
"
click_action
"
:
"
fcm.ACTION.HELLO
"
,
"
remote
"
:
true
},
},
"
priority
"
:
"
high
"
"
priority
"
:
"
high
"
}
}
...
@@ -78,16 +71,25 @@ class FirebaseClient {
...
@@ -78,16 +71,25 @@ class FirebaseClient {
this
.
_send
(
JSON
.
stringify
(
body
),
"
notification-data
"
);
this
.
_send
(
JSON
.
stringify
(
body
),
"
notification-data
"
);
}
}
_send
(
body
,
type
)
{
async
_send
(
body
,
type
)
{
if
(
FirebaseClient
.
KEY
===
'
YOUR_API_KEY
'
){
Alert
.
alert
(
'
Set your API_KEY in app/FirebaseConstants.js
'
)
return
;
}
let
headers
=
new
Headers
({
let
headers
=
new
Headers
({
"
Content-Type
"
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
,
"
Content-Length
"
:
parseInt
(
body
.
length
),
"
Authorization
"
:
"
key=
"
+
FirebaseConstants
.
KEY
"
Authorization
"
:
"
key=
"
+
FirebaseConstants
.
KEY
});
});
fetch
(
API_URL
,
{
method
:
"
POST
"
,
headers
,
body
})
try
{
.
then
(
response
=>
console
.
log
(
"
Send
"
+
type
+
"
response
"
,
response
))
let
response
=
await
fetch
(
API_URL
,
{
method
:
"
POST
"
,
headers
,
body
});
.
catch
(
error
=>
console
.
log
(
"
Error sending
"
+
type
,
error
));
response
=
await
response
.
json
();
if
(
!
response
.
success
){
Alert
.
alert
(
'
Failed to send notification, check error log
'
)
}
}
catch
(
err
)
{
Alert
.
alert
(
err
&&
err
.
message
)
}
}
}
}
}
...
...
Examples/simple-fcm-client/ios/SimpleFcmClient.xcodeproj/project.pbxproj
View file @
720709e4
...
@@ -422,6 +422,14 @@
...
@@ -422,6 +422,14 @@
name
=
Products
;
name
=
Products
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
};
};
3AF0A6071F7BE4DC004B899F
/* Recovered References */
=
{
isa
=
PBXGroup
;
children
=
(
692E216422234A4CB6A7A838
/* libRNFIRMessaging.a */
,
);
name
=
"Recovered References"
;
sourceTree
=
"<group>"
;
};
4339BFC21DAEBA3900F53B62
/* Products */
=
{
4339BFC21DAEBA3900F53B62
/* Products */
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
...
@@ -497,6 +505,7 @@
...
@@ -497,6 +505,7 @@
00E356EF1AD99517003FC87E
/* SimpleFcmClientTests */
,
00E356EF1AD99517003FC87E
/* SimpleFcmClientTests */
,
83CBBA001A601CBA00E9B192
/* Products */
,
83CBBA001A601CBA00E9B192
/* Products */
,
7E63D0154B6803F90ADF7C78
/* Pods */
,
7E63D0154B6803F90ADF7C78
/* Pods */
,
3AF0A6071F7BE4DC004B899F
/* Recovered References */
,
);
);
indentWidth
=
2
;
indentWidth
=
2
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
...
...
Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m
View file @
720709e4
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
[
RNFIRMessaging
willPresentNotification
:
notification
withCompletionHandler
:
completionHandler
];
[
RNFIRMessaging
willPresentNotification
:
notification
withCompletionHandler
:
completionHandler
];
}
}
-
(
void
)
userNotificationCenter
:(
UNUserNotificationCenter
*
)
center
didReceiveNotificationResponse
:(
UNNotificationResponse
*
)
response
withCompletionHandler
:(
void
(
^
)())
completionHandler
-
(
void
)
userNotificationCenter
:(
UNUserNotificationCenter
*
)
center
didReceiveNotificationResponse
:(
UNNotificationResponse
*
)
response
withCompletionHandler
:(
void
(
^
)(
void
))
completionHandler
{
{
[
RNFIRMessaging
didReceiveNotificationResponse
:
response
withCompletionHandler
:
completionHandler
];
[
RNFIRMessaging
didReceiveNotificationResponse
:
response
withCompletionHandler
:
completionHandler
];
}
}
...
...
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