GithubHelp home page GithubHelp logo

roy2651 / react-native-getui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getuilaboratory/react-native-getui

0.0 2.0 0.0 90.15 MB

getui react native

JavaScript 36.92% Java 18.36% Python 4.26% Objective-C 40.46%

react-native-getui's Introduction

react-native-getui (请使用版本@1.1.25)

react-native-getui 是个推官方开发的 React Native 插件,使用该插件可以方便快速地集成推送功能。

环境

  • React Native Version : 0.42(demo中使用的rn版本),理论上可以任意使用其他任何RN版本
  • react-native-getui >= 1.1.23
  • taobao的源和npm源版本可能存在不一致

安装

使用 npm 自动安装

在您的项目根目录下执行

npm install react-native-getui -save
react-native link
npm run GetuiConfigure <yourAppId> <yourAppKey> <yourAppSecret>  <yourModuleName>
// yourModuleName 指的是你的 Android 项目中的模块名称(对 iOS 没有影响,不填写的话默认值为 app)
// 举个列子:
npm run GetuiConfigure DI1jwW3FtZ6kGDeY5dk0Y9 DQCk2V8Jev9hqhWDU94PF9 Rtyp5trKUt8HSyzD8zRXX7 app

注意:

  • 如果在执行GetuiConfigure 自动安装脚本时发生错误,请使用手动安装方式。

  • yourAppId/yourAppKey/yourAppSecret 需要去 个推官网 注册后,在后台配置获取。

  • 在 iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下如路径:

$(SRCROOT)/../node_modules/react-native-getui/ios/RCTGetuiModule
  • 您的工程目录/android/app/src/main/{您的包名}/MainActivity的onCreate中调用
GetuiModule.initPush(this);

注意:

  • 有可能您的MainActivity中未重写onCreate方法,如果未重写,请重写onCreate方法,方法如下:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GetuiModule.initPush(this);
    }

如果您使用Android Studio作为IDE,Android Studio会自动为您import 相应的类名,如果您使用其他的IDE,请import相关的类

import android.os.Bundle;
import com.getui.reactnativegetui.GetuiModule;

手动安装

1、

npm install react-native-getui -save

2、

react-native link

3、 Xcode 工程配置

4、 Android Studio 工程配置

5、在 iOS 工程中如果找不到头文件需要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下如路径:

$(SRCROOT)/../node_modules/react-native-getui/ios/RCTGetuiModule

订阅消息

1.payload透传消息回调

2.cid 拿到clientId的回调

3.notificationArrived通知消息到达的回调

4.notificationClicked通知消息点击的回调

var { NativeAppEventEmitter } = require('react-native');

var receiveRemoteNotificationSub = NativeAppEventEmitter.addListener(
    'receiveRemoteNotification',
    (notification) => {
        switch (notification.type) {
            case "cid":
                Alert.alert('初始化获取到cid',JSON.stringify(notification))
                break;
            case 'payload':
                Alert.alert('payload 消息通知',JSON.stringify(notification))
                break
            case 'cmd':
                Alert.alert('cmd 消息通知', 'cmd action = ' + notification.cmd)
                break
            case 'notificationArrived':
                Alert.alert('notificationArrived 通知到达',JSON.stringify(notification))
                break
            case 'notificationClicked':
                Alert.alert('notificationArrived 通知点击',JSON.stringify(notification))
                break
            default:
                break
        }
    }
);

var clickRemoteNotificationSub = NativeAppEventEmitter.addListener(
    'clickRemoteNotification',
    (notification) => {
        Alert.alert('点击通知',JSON.stringify(notification))
    }
);

示例

  • 我们提供了一个demo供开发者参考对照 demo

  • 新版本插件new demo

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.