GithubHelp home page GithubHelp logo

react-native-jpush's Introduction

react-native-jpush

React Native的极光推送插件, react-native版本需要0.17.0及以上

如何安装

首先安装npm包

npm install react-native-jpush --save

link

rnpm link

Note: rnpm requires node version 4.1 or higher

iOS工程配置

a.在工程target的Build Phases->Link Binary with Libraries中加入liz.tbd、CoreTelephony.framework、Security.framework

b.在你的工程中创建一个新的Property List文件,并将其命名为PushConfig.plist,文件所含字段如下:

CHANNEL
	指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如:App Store。
APP_KEY
	与JPush上申请的 AppKey 一致。
APS_FOR_PRODUCTION
	0 (默认值)表示采用的是开发证书,1 表示采用生产证书发布应用。
	注:此字段的值要与Build Settings的Code Signing配置的证书环境一致。

c.在AppDelegate.m中加入

#import "RCTJPush.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  
  [RCTJPush application:application didFinishLaunchingWithOptions:launchOptions];
  
  ...
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RCTJPush application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
  [RCTJPush application:application didReceiveRemoteNotification:notification];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  [RCTJPush application:application didReceiveRemoteNotification:notification];
  completionHandler(UIBackgroundFetchResultNewData);
}

Android配置

android/app/build.gradle里,defaultConfig栏目下添加如下代码:

manifestPlaceholders = [
    JPush_APPID: "JPush的APPID",	//在此修改JPush的APPID
    APP_CHANNEL: "应用渠道号"		//应用渠道号
]

如何使用

引入包

import JPush , {JpushEventReceiveMessage, JpushEventOpenMessage} from 'react-native-jpush'

在你的根Component中加入下面代码

componentDidMount() {
    JPush.requestPermissions()
    this.pushlisteners = [
        JPush.addEventListener(JpushEventReceiveMessage, this.onReceiveMessage.bind(this)),
        JPush.addEventListener(JpushEventOpenMessage, this.onOpenMessage.bind(this)),
    ]
}
componentWillUnmount() {
    this.pushlisteners.forEach(listener=> {
        JPush.removeEventListener(listener);
    });
}
onReceiveMessage(message) {
}
onOpenMessage(message) {
}

react-native-jpush's People

Contributors

lvbingru avatar

Watchers

James Cloos avatar Billy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.