Step to setup Firebase Push Notifications in react native applications

buildscript { // ... dependencies { // ... classpath 'com.google.gms:google-services:4.0.1' } }
apply plugin: 'com.google.gms.google-services'
dependencies { // This should be here already implementation project(':react-native-firebase') // Firebase dependencies implementation "com.google.android.gms:play-services-base:16.0.1" implementation "com.google.firebase:firebase-core:16.0.4"
buildscript { repositories { google() // <-- Check this line exists and is above jcenter jcenter() } }
classpath 'com.android.tools.build:gradle:3.2.0'
implementation project(':react-native-firebase')
allprojects { repositories { google() // <-- Add this line above jcenter jcenter() maven { } } }
dependencies { implementation "com.google.firebase:firebase-messaging:17.3.4" }
// ... import io.invertase.firebase.RNFirebasePackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // <-- Add this line public class MainApplication extends Application implements ReactApplication { // ... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new RNFirebasePackage(), new RNFirebaseMessagingPackage() // <-- Add this line ); } }; // ... }
<application ...> <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service> </application>
public function fcm($title, $message, $type, $notification_ids =array()){ define( 'API_ACCESS_KEY', 'Your_api_key'); $registrationIds = $notification_ids; $msg = array ( 'title' => $title, 'message' => $message, 'summaryText' => 'The internet is built on cat pictures', 'click_action' => 'FCM_PLUGIN_ACTIVITY', 'vibrate' => 1, 'sound' => 1, 'type' => $type ); $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result; }

--

--

--

2Hats Logic is a technology service company provide customized web and mobile application development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Angular JS Parent-Child Controller Communication and Best Practice for usage

Why React JS is so fast ❓ 🚀

13 [HILARIOUS] Programming Jokes and a (Bonus Tip)

My two weeks of Generasi Gigih class, so far…

https://concept-tees.myspreadshop.com/i+got+this+thought+bubble-A5c2487b1205176394af290d3

https://concept-tees.myspreadshop.com/bubbling+gold+banner-A5d1bef49f9376450b074942d

Dynamic Elements in Angular with Structural Layout

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
2Hats Logic Solutions

2Hats Logic Solutions

2Hats Logic is a technology service company provide customized web and mobile application development.

More from Medium

React Native vs Flutter

Which One Is Best For Developing Mobile Apps? React Native or Flutter

React Native Notes 29: Firebase Google Sign-in Problem on Android APK

Flutter v/s React Native: Choose the Right Framework for your Business Application