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-xmpush

v2.0.0

Published

集成小米推送

Downloads

18

Readme

react-native-mipush

该项目基于小米推送,使用前,请先在小米开发者后台注册app,并获取对应的appid与appkey。

开发环境:xcode8、react-native

##作者

QQ: 289459798 QQ群: 161263093

欢迎更多的喜欢开源的小伙伴加入

##安装

// rn > 0.6.x
npm install react-native-xmpush --save 

// rn > 0.4.x
npm install [email protected] --save 

// rn < 0.4.x
npm install [email protected] --save 
react-native link

##android

项目的AndroidManifest.xml文件中增加下面代码:

// 一下代码放在 applacation 标签下
<meta-data android:name="MIPUSH_APPID" android:value=":1111"/>
        <meta-data android:name="MIPUSH_APPKEY" android:value=":2222"/>

// 1111 替换成在小米申请的appid
// 2222 替换成在小米申请的appkey

// 千万注意要保留数字前面的冒号

##ios

==必须通过xcode8开发的项目==

ios需要先制作推送证书,具体教程请自行百度。

本项目是基于RCTPushNotification,请将RCTPushNotification拖动到Libraries目录下。

添加所需依赖库:

  • UserNotifications.framework
  • libresolv.dylib(tbd)
  • libxml2.dylib(tbd)
  • libz.dylib(tbd)
  • SystemConfiguration.framework
  • MobileCoreServices.framework
  • CFNetwork.framework
  • CoreTelephony.framework

targetCapabilities选项卡打开Push Notifications

targetBuild Phases选项卡添加Link Binary With Libraries:

libRCTPushNotification.a libRCTMIPushModule.a

在targets->Build Settings下面搜索 Header Search Paths,添加

$(SRCROOT)/../node_modules/react-native-xmpush/ios/RCTMIPushModule

$(SRCROOT)/../node_modules/react-native/Libraries/PushNotificationIOS

设置为 recursive

打开工程下Info.plist文件为源代码形式打开,添加以下信息:

<key>MiSDKAppID</key>
<string>1000888</string>
<key>MiSDKAppKey</key>
<string>500088888888</string>
<key>MiSDKRun</key>
<string>Online</string>

修改 AppDelegate.m 文件:

...
#import "RCTMIPushModule.h"
#import "RCTPushNotificationManager.h"
...

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

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{

  [RCTMIPushModule application:application didRegisterUserNotificationSettings:notificationSettings];
  ...
}

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

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

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [RCTMIPushModule application:application didReceiveLocalNotification:notification];
  ...
}

// ios 10
// 应用在前台收到通知
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  [RCTMIPushModule userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
  ...
}

// 点击通知进入应用
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  [RCTMIPushModule userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
  ....
  completionHandler();
}

##RN中使用

Demo:

android

...

import MIPush from 'react-native-mipush';

...
componentWillUnmount() {

    MIPush.unsetAlias("oooooo");
    MIPush.removeEventListener("xmpush_click");
    MIPush.removeEventListener("xmpush_notify");
}

componentDidMount() {

    MIPush.setAlias("oooooo");

    MIPush.addEventListener("xmpush_click", (notification) => {

      console.log("app运行过程中点击通知:", notification);
    });

    MIPush.addEventListener("xmpush_notify", (notification) => {

      console.log("app接收到通知:", notification);
    });

    MIPush.getInitialNotification((notification) => {

      console.log("app关闭时获取点击通知消息:", notification);

    });

  }

ios

...
componentWillUnmount() {

    MIPush.unsetAlias("bbbbbb");
    MIPush.removeEventListener("notification");
  }

  componentDidMount() {

    MIPush.setAlias("bbbbbb");

	MIPush.setBadgeNumber(0);   // 每次进入app将角标设置为0
    MIPush.addEventListener("notification", (notification) => {

      console.log("app接收到通知:", notification);
      
      // 弹出确认框
    });

    MIPush.getInitialNotification((notification) => {

      console.log("app关闭时获取点击通知消息:", notification);
	  // 弹出确认框
    });

  }
  ...

暂支持的所有方法:

/**
 * 设置别名
 * @param text
 */
setAlias(text);

/**
 * 注销别名
 * @param text
 */
unsetAlias(text);

/**
 * 设置主题,类似tag
 * @param text
 */
subscribe(text);

/**
 * 注销主题
 * @param text
 */
unsubscribe(text);

/**
 * 设置账号,一个账号需要多台设备接收通知
 * @param text
 */
setAccount(text);

/**
 * 注销账号
 * @param text
 */
unsetAccount(text);

/**
 *
 * @param type
 * ios :
 * notification => 监听收到apns通知
 * localNotification => 监听收到本地通知
 * register => 注册deviceToken 通知
 *
 * android :
 * xmpush_notify => 监听收到推送
 * xmpush_click => 监听推送被点击
 * xmpush_message => 监听收到透传消息
 * @param handler
 */
addEventListener(type, handler);

removeEventListener(type);

/**
 * 发送一个本地通知
 * @param notification
 */
presentLocalNotification(notification);

/**
 * 清除指定通知
 * @param notifyId
 * ios : userInfo
 * android : id
 */
clearNotification(notifyId);

/**
 * 清除所有通知
 */
clearNotifications();

/**
 * 设置角标,仅支持ios
 * @param num
 */
setBadgeNumber(num);

/**
 * 通过点击通知启动app
 * @param handler
 */
getInitialNotification(handler);