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

react-native-pure-xinge-push

v0.2.5

Published

react native xinge push

Downloads

18

Readme

react-native-pure-xinge-push

信鸽 SDK 版本:

  • ios: 3.3.7
  • android: 4.3.7

安装

npm i react-native-pure-xinge-push

// 如果react-native的版本>=0.60,会自动link,无需执行下面的命令
react-native link react-native-pure-xinge-push

配置

iOS

Capabilities 打开推送

修改项目 AppDelegate.m,如下:

#import <RNTXingePushModule.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  // 这里有一堆固定的代码

  // 最后加上这句
  [RNTXingePushModule didFinishLaunchingWithOptions:launchOptions];

  return YES;
}

// 加上这句
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
  [RNTXingePushModule didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

@end

Android

android/app/build.gradle 加上这段

buildTypes {
    // 测试包
    debug {
        // 这里一般有一些别的配置

        // 重点是这三个配置项
        manifestPlaceholders = [
            XG_ACCESS_ID: "信鸽 accessId",
            XG_ACCESS_KEY: "信鸽 accessKey",
            HW_APPID: "华为 appId"
        ]
    }
    // 线上包
    release {
        // 这里一般有一些别的配置

        // 重点是这三个配置项
        manifestPlaceholders = [
            XG_ACCESS_ID: "信鸽 accessId",
            XG_ACCESS_KEY: "信鸽 accessKey",
            HW_APPID: "华为 appId"
        ]
    }
}

用法

import XingePush from "react-native-pure-xinge-push";

// 安卓开启厂商推送
XingePush.enableOtherPush(true);

// 配置小米 (string, string)
XingePush.setXiaomi(appId, appKey);
// 配置魅族 (string, string)
XingePush.setMeizu(appId, appKey);

// 配置华为,appId 写在 `android/app/build.gradle`,这里不用传了
// 这种脑残的方案也不知道是华为搞的还是信鸽搞的
// 开启华为的调试,如果不用就不调
XingePush.setHuaweiDebug(true);

// 安卓逻辑到此结束

// 是否需要开启信鸽调试
XingPush.setDebug(true);

// 配置信鸽 (number, string)
// 启动成功会触发 register 事件
XingePush.start(xgAccessId, xgAccessKey);

// 停止接收推送
XingPush.stop();

// 监听事件
let binder = XingePush.addEventListener("register", function(data) {
  // 信鸽错误码
  // ios: https://xg.qq.com/docs/ios_access/ios_returncode.html
  // android: https://xg.qq.com/docs/android_access/android_returncode.html
  if (data.error) {
    return;
  }

  // 获取 deviceToken
  data.deviceToken;

  // 绑定帐号 (string)
  XingePush.bindAccount("account");

  // 解除绑定帐号 (string)
  XingePush.unbindAccount("account");

  // 绑定标签 (Array)
  XingePush.bindTags(["tag1", "tag2"]);

  // 解除绑定标签 (Array)
  XingePush.unbindTags(["tag1", "tag2"]);
});
// 解绑事件
binder.remove();

// 透传消息
XingePush.addEventListener("message", function(message) {
  // message 类型为对象
  // ios 通过静默消息实现
  // android 通过透传消息实现
  // 为了跨平台的兼容性,message 的数据全部来自 custom content
  // 安卓有些第三方厂商支持透传消息,却不支持 custom content
  // 因此最好把透传消息的 content 字段设置为自定义参数的序列化 JSON 形式,比如 content = "{"cmd":"alert","content":"xxx"}"
  // 此外,某些厂商通道会给 content 自动再加一层 content,导致调用 getContent() 方法获取到的真实 content 格式为 "{content: "传入的content"}",因此建议 JSON 不要以 {"content": 开头,因为我会把自动加的这层给去掉。
});

// 推送消息
XingePush.addEventListener("notification", function(notification) {
  // 推送是否弹出展现了
  notification.presented;

  // 推送是否被用户点击了
  notification.clicked;

  // 自定义的键值对
  notification.custom_content;

  // 推送消息主体,安卓没法保证能取到正确的值,最好不要依赖这个字段
  notification.body;
});

声明

保证会及时跟进最新版 SDK,放心使用。

打赏

走过路过的都打赏一点吧,给点动力继续更新。

微信

支付宝