npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alivepush/react-native-xg

v0.0.6

Published

react-native-xg封装了信鸽的推送API,集成了ios,android(包括华为,小米,魅族)的推送功能.

Downloads

3

Readme

react-native-xg

react-native-xg封装了信鸽的推送API,集成了ios,android(包括华为,小米,魅族)的推送功能.

  • react-native-xg测试使用的是[email protected]进行测试的,如果在其他版本使用中有问题请在issues中说明
  • android使用的信鸽版本为com.tencent.xinge:xinge:3.2.4-beta,对应的版本号可以在android/build.gradle中查看
  • 文档请参考API Document & Examples
  • app demo

npm version npm license npm download npm download

Getting started

$ npm install @alivepush/react-native-xg --save

Mostly automatic installation

$ react-native link @alivepush/react-native-xg

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-xg and add RNReactNativeXg.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNReactNativeXg.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.alivepush.xg.RNReactNativeXgPackage; to the imports at the top of the file
  • Add new RNReactNativeXgPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-xg'
    project(':react-native-xg').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-xg/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-xg')

集成

android配置

修改build.gradle配置文件

android {
    defaultConfig {
        manifestPlaceholders = [
            //可选填,可以通过代码进行设置
            XG_ACCESS_ID : "",
            //可选填,可以通过代码进行设置
            XG_ACCESS_KEY: "",
            //可选填,如果需要使用华为推送就必须填写
            HW_APPID     : "",
            //可选填,如果需要使用小米推送就必须填写
            PACKAGE_NAME : ""
        ]
    }
}

React Native 实现

使用快速注册接口

import React,{Component} from "react"
import {View} from "react-native"
import xg from '@alivepush/react-native-xg'

class App extends Component{
    render(){
        //do something
    }
    componentDidMount(){
        /*
          默认开启第三方推送服务
          如果accessid和accesskey已经配置过了,可以直接传递null
          如:

          xg.register("miAppId","miAppKey","mzAppId","mzAppKey",null,null,debug,(token,code)=>{
              console.log(`code=${code},token=${token}`);
          })

        */
        xg.register("miAppId","miAppKey","mzAppId","mzAppKey","access_id","access_key",debug,(token,code)=>{
            console.log(`code=${code},token=${token}`);
        })
    }
}

单步实现信鸽推送

import React,{Component} from "react"
import {View} from "react-native"
import xg from '@alivepush/react-native-xg'

class App extends Component{
    render(){
        //do something
    }
    componentDidMount(){

        //开启日志
        //PS:当发布到生产环境时最好不要开启日志
        //这里其实可以根据环境变量来确定是否开启日志
        //xg.enableDebug(process.env.NODE_ENV==="development");
        xg.enableDebug(true);

        //设置access id
        xg.setAccessId("ACCESS_ID");

        //设置access key
        xg.setAccessKey("ACCESS_KEY");

        //如果需要监听注册的回调有两种方式
        //第一种:xg.addListener("registerresult",()=>{})
        //第二种:xg.registerPush(()=>{});
        //这里我们使用第一种
        const listener=xg.addListener("registerresult",(...args)=>{
            listener.remove();
            console.log("注册结果",args);
        })

        //开始注册
        xg.registerPush();

        //如果我们是点击通知栏触发的app启动需要监听`fetchLastClickMessage`
        xg.fetchLastClickMessage(message=>{
            //可以处理通知栏过来的消息
        });
    }
}