Code Monkey home page Code Monkey logo

jpush-react-native's Introduction

JPush-React-Native

ChangeLog

  1. 从RN-JPush2.7.5开始,重新支持TypeScript
  2. 由于RN-JCore1.6.0存在编译问题,从RN-JCore1.7.0开始,还是需要在AndroidManifest.xml中添加配置代码,具体参考 配置-2.1 Android

1. 安装

npm install jpush-react-native --save
  • 注意:如果项目里没有jcore-react-native,需要安装

    npm install jcore-react-native --save
    

安装完成后连接原生库 进入到根目录执行
react-native link

react-native link jpush-react-native
react-native link jcore-react-native

2. 配置

2.1 Android

  • build.gradle

    android {
          defaultConfig {
              applicationId "yourApplicationId"           //在此替换你的应用包名
              ...
              manifestPlaceholders = [
                      JPUSH_APPKEY: "yourAppKey",         //在此替换你的APPKey
                      JPUSH_CHANNEL: "yourChannel"        //在此替换你的channel
              ]
          }
      }
    
    dependencies {
          ...
          implementation project(':jpush-react-native')  // 添加 jpush 依赖
          implementation project(':jcore-react-native')  // 添加 jcore 依赖
      }
    
  • setting.gradle

    include ':jpush-react-native'
    project(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')
    include ':jcore-react-native'
    project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')
    
  • AndroidManifest.xml

    <meta-data
    	android:name="JPUSH_CHANNEL"
    	android:value="${JPUSH_CHANNEL}" />
    <meta-data
    	android:name="JPUSH_APPKEY"
    	android:value="${JPUSH_APPKEY}" />    
    

2.2 iOS

注意:您需要打开ios目录下的.xcworkspace文件修改您的包名

2.2.1 pod

pod install
  • 注意:如果项目里使用pod安装过,请先执行命令

    pod deintegrate
    

2.2.2 手动方式

  • Libraries

    Add Files to "your project name"
    node_modules/jcore-react-native/ios/RCTJCoreModule.xcodeproj
    node_modules/jpush-react-native/ios/RCTJPushModule.xcodeproj
    
  • Capabilities

    Push Notification --- ON
    
  • Build Settings

    All --- Search Paths --- Header Search Paths --- +
    $(SRCROOT)/../node_modules/jcore-react-native/ios/RCTJCoreModule/
    $(SRCROOT)/../node_modules/jpush-react-native/ios/RCTJPushModule/
    
  • Build Phases

    libz.tbd
    libresolv.tbd
    UserNotifications.framework
    libRCTJCoreModule.a
    libRCTJPushModule.a
    

3. 引用

3.1 Android

参考:MainApplication.java

3.2 iOS

参考:AppDelegate.m

3.3 js

参考:App.js

4. API

详见:index.js

5. 其他

  • 集成前务必将example工程跑通
  • 如有紧急需求请前往极光社区
  • 上报问题还麻烦先调用JPush.setLoggerEnable(true},拿到debug日志

jpush-react-native's People

Contributors

andy6shen avatar arniu avatar baurine avatar bomee avatar chj-damon avatar django-wong avatar gcmsg avatar guhungry avatar huangminlinux avatar huangshuni avatar huhuanming avatar jiguangdev avatar joshlipan avatar kenchoi1992 avatar lcterry avatar linytsysu avatar lixiaohang000 avatar marekchen avatar messense avatar originerd avatar pangutech avatar phecda avatar prlsir avatar rokiegodfather avatar skill20 avatar sunnylqm avatar x13945 avatar xwartz avatar yukirin000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpush-react-native's Issues

按上面配置好后,项目能正常运行,但是接受不到推送

"dependencies": {
"react-native": "^0.20.0",
"react-native-jpush": "^1.0.8"
}
上面是我的版本号,完全按上面配置后,请问我发送消息
b2fd69c2-1927-48a3-80a2-cb6ddd3a801f
请问这是什么原因,难道按上面配置完后还不能发布消息么,或者客户端还需要单独在极光注册么?

安卓推送问题

安卓按文档配置后,能拿到注册ID,推送后台也显示推送成功,但是手机端消息接受不到,后台目标|成功一直是1|0,还一直有推送提示,“Jpush提示:缺少统计代码 检测到集成SDK未添加统计代码”。

请问iOS推送角标怎么设置

运行项目后角标一直是1,不管推送多少条都没有变化;当我在AppDelegate.m添加了
-(void)applicationDidEnterBackground:(UIApplication *)application {

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; //0 设置为0 ,可以设置为任意的值
}
方法后,还是没有实现:每推送一下消息角标加一,每点击一下图标,角标减一的效果。
请问这个效果在ios怎么实现? @

Android 推送有延迟

Android 的推送有延迟的,延迟时间不等,最后全部收到了,麻烦问下可以优化吗?谢谢

这个插件按照说明,没有运行起来

这个插件按照说明,没有运行起来,整个Android的目录结构和官方例子不同的地方太多,上手有点难。希望能跟官方例子的目录结构保持一致,并给出详细的说明,谢谢。

iOS下,无法找到kJPFDidReceiveRemoteNotification

是不是在JPUSHService.h文件中,缺少了此定义?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  // 取得 APNs 标准信息内容
  [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];
}

//iOS 7 Remote Notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:  (NSDictionary *)userInfo fetchCompletionHandler:(void (^)   (UIBackgroundFetchResult))completionHandler {
  [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];
}

iOS0

iOS10 貌似无法收到推送通知

Apikey的配置能不能提到其他地方去

现在的Apikey的配置是在 jpush-react-plugin 的build.gradle文件里面,
但是这个文件 是在 node_modules 目录里面的,显然是不在git里面的。

如果有多个人开发这个同一个项目的话,那他把项目clone到本地之后,还需要手动去修改这些东西,才能生效。如果他忘记了,或者不知道的还,那不就坑爹了。

建议把这个东西 弄到 MainActivity 里面去。

android RN how addpackage

感谢这个组件!有些疑问,烦请各位指导!
不知道如何添加package,
项目使用版本分别为
"jpush-react-native": "^1.1.3",
"react": "15.3.1",
"react-native": "^0.32.0",

c7105c94-34a3-4eef-a6b1-c5189afe20ae

在我本地的项目里,路径为 项目/android/app/src/main/java/com/awesomeproject/MainActivity.java
内容显示为下
fe454e51-44b0-4b87-a359-5e1a6940efa1

配置完成后,发送消息无法接收问题

请问 我完全按照ReadMe重新配置好后,现在可以发送推送消息,但是仍然无法接受到消息,而且registrationid也没有
Uploading 00C91F32-A061-47AE-884B-5FAD20E8E553.png…

每次点击GET REGISTRATIONID 后 registrationid都变为null,请问能帮忙看下么 @KenChoi1992

Cannot read property 'setAlias' of undefined

首先,感谢提供这个组件!!!
  • IOS模拟器,在调用setAlias时出错,代码如下:

import JPushModule from 'jpush-react-native';
......... //其他代码
JPushModule.setAlias('283', ()=> {
console.log('-------success---------');
}, ()=> {
console.log('-------fail---------');
});

  • 错误描述:Cannot read property 'setAlias' of undefined
  • 版本信息:

"react": "15.2.1",
"react-native": "0.31.0",
"jpush-react-native": "^1.1.3",

请问如何设置版本号

我的项目是以前下载,如果在Android5.0真机运行需要把
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

1.3.1 => 1.2.0 不然是运行不起来的,但是加了jpush插件后,一开始我没改版本号(1.3.1)在模拟器上运行一切正常,但是当我要到真机运行时,并把版本号换成(1.2.0),项目能正常运行,但是发送通知后接受不到RegistrationId,也接受不到推送消息,请问这是什么原因啊? @

iOS设备在接收到一条推送通知时多次运行NativeAppEventEmitter.addListener('ReceiveNotification', )

iOS设备在接收到一条推送通知时多次重复运行NativeAppEventEmitter.addListener('ReceiveNotification', (notification)=>{console.log("推送通知");console.log(notification);})(Android端那三个函数没问题)
而我希望的是接收到一条推送消息就运行一次NativeAppEventEmitter.addListener('ReceiveNotification', (notification)=>{console.log("推送通知");console.log(notification);})

这算BUG吗

能更新一下文档不

虽然你们是官方维护的jpush,但是文档跟 reactnativecn的那个比真的差挺远的。不过貌似你们用的API比较新。

用react native的大部分都是前端程序员(说的就是我),一些涉及到原生应用的配置,看着都很头疼,有时候会被一些原生应用的基本概念挡在门外。

能花点时间整理一下文档不,尽可能写详细一点。

安卓编译错误

为什么安卓照着文档配置后,StopPush,ResumePush都提示Success,但是GetRegistrationID找不到,并且调试时返回-996错误,但是设备是联网的,并且核对了包名申请的APPKey应该没错。

配置好后无法接受消息

按上面配置好后,准备推送消息,发现
f37df91f-a112-42cc-a5e5-8decb3d96e75

"dependencies": {
"jpush-react-native": "^0.1.0",
"react-native": "^0.20.0"
}

界面切换导致收不到推送

我的APP Home页可以收到推送 一但切换到另外一个页面就会收不到推送了 只有重启APP才能收到之前的推送消息

点击推送通知唤醒应用问题

@KenChoi1992 你好,我试了下新版本还是有些问题:

  • 按 home 键应用切换到后台,可以接收到推送,点击通知栏的推送通知,无法把后台应用切换到前台。

把下面代码改成老版本,可以把后台应用切换到前台

// v0.1.1 版本
Logger.d(TAG, "用户点击打开了通知");
WritableMap map = Arguments.fromBundle(bundle);
mRAC.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("openNotification", map);
Intent intent = new Intent();
if (mModule != null && mModule.getCurrentActivity() != null) {
    intent.setClass(context, mModule.getCurrentActivity().getClass());
    Logger.d(TAG, "context.getClass: " + mModule.getCurrentActivity().getClass());
    intent.putExtras(bundle);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

旧版本可以把应用切换到前台显示

v0.1.0
Logger.d(TAG, "用户点击打开了通知");
WritableMap map = Arguments.fromBundle(bundle);
mRAC.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("openNotification", map);
Intent intent = new Intent();
if (mModule != null && mModule.mContext != null) {
    intent.setClass(context, mModule.mContext.getClass());                    
    intent.putExtras(bundle);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

  • 退出应用,可以接收到推送,但点击通知栏的推送通知,无法唤醒应用。
  • 环境:
    react-native 版本:0.28.0
    jpush-react-native 版本:0.1.1
    android 版本:htc 802d 5.0.2

Error Code: 6003

已按照要求配置,提示 init success后,提示 'Error Code 6003'. 请问什么原因?

[Android] 应用退出后,收到通知报错

我是通过长按home清除任务发现这个错误的。正常退出没有这个错误。
之前尝试使用过另一款推送服务,也是有这个错误。

清除任务后,收到通知,会报一个错误。
点击通知也会报一个错误。
然后再推送就收不到通知了。
如果再打开应用的话,就会收到之前未收到的通知。

错误日志在下面

react-native 0.30.0编译出错

duplicate symbol _kJPFServiceErrorNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) duplicate symbol _kJPFNetworkDidRegisterNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) duplicate symbol _kJPFNetworkDidSetupNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) duplicate symbol _kJPFNetworkDidLoginNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) duplicate symbol _kJPFNetworkDidCloseNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) duplicate symbol _kJPFNetworkDidReceiveMessageNotification in: /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPushModule.a(JPUSHService.o) /Users/yangguobao/Library/Developer/Xcode/DerivedData/ListenerApp-fkckisnbhcqpsreucevpueraijvi/Build/Products/Debug-iphonesimulator/libRCTJPush.a(APService.o) ld: 6 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
错误如图,请问是什么原因?

统计API

/**
* rn 0.29.0 以下版本,请使用此方法,并去掉 MainApplication 文件, 0.29.0 以上版本请去掉这些注释代码
* 注意改变其中的 JSMainModuleName 的路径(因为此版本适配了 rn 0.30.0, index.android.js 放在了项目目录下)
* 相应地,index.android.js 中 push_activity.js,set_activity.js的引用路径也要改变(参考 index.android.js)
*/
// private ReactRootView mReactRootView;
// private ReactInstanceManager mReactInstanceManager;
// private boolean SHUTDOWN_TOAST = false;
// private boolean SHUTDOWN_LOG = false;

// @OverRide
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// mReactRootView = new ReactRootView(this);
// mReactInstanceManager = ReactInstanceManager.builder()
// .setApplication(getApplication())
// .setBundleAssetName("index.android.bundle")
// .setJSMainModuleName("react-native-android/index.android")
// .addPackage(new MainReactPackage())
// .addPackage(new JPushPackage(SHUTDOWN_TOAST, SHUTDOWN_LOG))
// .setUseDeveloperSupport(BuildConfig.DEBUG)
// .setInitialLifecycleState(LifecycleState.RESUMED)
// .build();
// mReactRootView.startReactApplication(mReactInstanceManager, "PushDemoApp", null);
//
// setContentView(mReactRootView);
// }

这里的意思是如果>0.30,uncomment掉这段代码?setJSMainModuleName应该设置自己项目的index?

JPUSHService registerForRemoteNotificationTypes

Hi,

I want to show the disallow allow push notification dialog more later than app launches(didFinishLaunchingWithOptions).

In here, the document recommended to call that method in didFinishLaunchingWithOptions callback.

But can i call this when i want? Is there a javascript exported method?

I have analysed some of your lib code, and found that,

jpush-react-native/ios/RCTJPushModule/RCTJPushModule/RCTJPushModule.m

LIne #59

//RCT_EXPORT_METHOD(setupPush:(NSString *)name) {
//  if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//    //可以添加自定义categories
//    [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
//                                                      UIUserNotificationTypeSound |
//                                                      UIUserNotificationTypeAlert)
//                                          categories:nil];
//  } else {
//    //categories 必须为nil
//    [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
//                                                      UIRemoteNotificationTypeSound |
//                                                      UIRemoteNotificationTypeAlert)
//                                          categories:nil];
//  }
//
//  [JPUSHService setupWithOption:nil appKey:appKey
//                        channel:channel apsForProduction:isProduction];
//}

this code is commented.

Can i uncomment this, and use this method? Is there a side-effect that I have to concern?

IOS点击通知不触发事件?

NativeAppEventEmitter.addListener(
'ReceiveNotification',
(notification) => console.log(notification)
);

这段代码无效果
已经添加了

为了在收到推送点击进入应用能够获取该条推送内容需要在 AppDelegate.m didReceiveRemoteNotification 方法里面添加 [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo] 方法

ReactNative安卓下点击推送通知, 会额外打开一个activity?

ReactNative: v0.29
模拟器
android: v4.4.4

推送通知可以正常到达. 如果应用已经打开(不管是前台还是后台), 点击通知栏的通知, 会重新打开一个"实例"(不确定是不是打开了一个新的Activity还是其他什么, 安卓这个我也不是很懂). 这个实例可以通过Back键退出, 退出后就到了原来打开的界面里了.

请问是否哪里配置不对?

iOS10

iOS10 貌似无法收到推送通知

谢谢官方提供的这个插件

看了一下这个插件,感觉要集成非常不方便,如果我是要集成到我现有的项目要怎么做,不是使用这个APP 目录

建议详细书写配置文档

使用react的绝大部分是不懂ios或安卓的,我觉得您应该脱离jush文档,自己重新详细定义一份文档。

到底哪些必须配置,哪些不用配置,而不是一个链接;

仅是建议,望参考。

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.