JSPM

react-native-gcm

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q40153F
  • License MIT

Google Cloud Messaging for React Native

Package Exports

  • react-native-gcm

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-gcm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Google Cloud Messaging for React Native

Install

install react-native-gcm

$ npm install react-native-gcm

Add GCM Pod to your Podfile

pod Google/CloudMessaging`

Add Source files to your project

  • GCM.swift
  • GCMBridge.h
  • GCMBridge.m

Add ObjC / Swift Bridge Header

#import "RCTBridge.h"
#import "RCTBridgeModule.h"
#import "RCTEventDispatcher.h"
#import <Google/CloudMessaging.h>

Add required methods to your AppDelegate

  • See AppDelegate_Example.swift for integration example

Usage

import gcm from 'react-native-gcm';

Register for Push Notifications

gcm.register()

Subscribe to topic

gcm.topicSubscribe('/topics/test', (err, res) => {});

Unsubscribe from topic

gcm.topicUnsubscribe('/topics/test', (err, res) => {});

Send upstream message

gcm.sendMessage({
    id: '' // unique message id
    to: '', // recip id
    ttl: 500 // optional time to live
    message: {}, // msg data
});

Events

GCM has all "EventEmitter" methods.

// Connected to GCM socket
gcm.on('connection', (res) => {});

// Disconnected from GCM socket
gcm.on('disconnect', (res) => {});

// Client registered with gcm
gcm.on('registeredClient', (res) => {});

// Application entered background
gcm.on('enteredBackground', (res) => {});

// Application became active again
gcm.on('becameActive', (res) => {});

// Received message from GCM
gcm.on('message', (res) => {});

License

MIT