Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Example for crossplatform push notifications with node.js and React Native

License

NotificationsYou must be signed in to change notification settings

alex-friedl/crossplatform-push-notifications-example

Repository files navigation

This is an example for a Crossplatform Push-Notification setup that works for both Android and iOS.

The example comprises of a server application written innode.js that uses thenode-pushnotifications library and aReact Native app that demonstrates the usage of thereact-native-push-notification library and thereact-native-fcm library.

It includes an exampleFirebase application setup that works out of the box.In order to use your own Firebase application, replace thegoogle-services.json in theapp/android directory, respectively theGoogleService-Info.plistin theapp/iosdirectory with your own (downloadable in theFirebase Console).

Requirements

Setup

  • Optional: Install yarn (npm install yarn -g)
  • Runnpm install oryarn

Run demo application

Start server

  • Rundocker-compose up
  • Alternatively:
    • Start MongoDBmongod --dbpath=<yourDbPath>
    • Start servernpm run server

Run app

  • Start React Native app packagernpm run app-pkg
  • Connect a device or start a simulator
  • Run Android appnpm run android
  • Run iOS appnpm run ios

What's happening?

After application startup you should see a screen which displays your device token and the information that no notification has been received yet.

The device token should have been sent to the node.js server and stored in the MongoDB.

In order to send a sample push notification to all known device tokens executecurl http://localhost:3000/push or openhttp://localhost:3000/push in your local browser.

The application should now displayLast notification title: Crossplatform push is working.

Configuration options

Server

If you choose to run the backend locally without Docker, you can configure two parameters via environment variables:

  • DB_HOST: MongoDB host string
  • SERVER_PORT: HTTP port of the server application

App

The app uses thereact-native-config library to configure its environment.

You can edit theapp/.env file in order to configure the following:

Known issues

  • Usage ofreact-native-push-notification for iOS currently not functional. Help appreciated.

[8]ページ先頭

©2009-2025 Movatter.jp