JSPM

react-native-gcm

0.1.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q35015F
  • 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>

Usage

import gcm from 'react-native-gcm';

Register for Push Notifications

// Default permission {alert: true, badge: true, sound: true}
gcm.register(/*permission*/)

Set App Badge Value

// Set App Badge to value
gcm.setAppBadge(2, (newBadgeVal) => { });

// Increment App Badge value
gcm.setAppBadge(2, true, (newBadgeVal) => { });

Get App Badge Value

gcm.getAppBadge((badgeVal) => { });

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