React Native's Aurora push jpush-react-native hand Configuration

Source: Internet
Author: User

This is react native to configure the use of the Aurora push components, more commonly used https://github.com/jpush/jpush-react-native first put the component address, convenient for everyone to use the reference. If this everyone can not be configured to succeed, welcome everyone together into the pit exchange, there is a problem contact QQ379038610 (add notes to explain why)

Do not pull the useless, but also to wash sleep, directly configure themselves the steps of the iOS Aurora for everyone to post out
1, first of all, the project environment, signing certificate, everything is configured to start the integration of push under the premise

In the project current directory execution:

  npm install jpush-react-native --save

  rnpm link jpush-react-native

Note: If not installed RNPM first NPM install RNPM installation RNPM (Details Baidu ... )

2. After execution, open Xcode and add the following library to the Build Phases->link Binary with Libraries of the IOS project target

    • Libz.tbd
    • Coretelephony.framework
    • Security.framework
    • Cfnetwork.framework
    • Corefoundation.framework
    • Systemconfiguration.framework
    • Foundation.framework
    • Uikit.framework
    • Usernotifications.framework
    • Libresolv.tbd
    • Import header files in the AppDelegate.h file
#import <RCTJPushModule.h>#ifdef NSFoundationVersionNumber_iOS_9_x_Max#import <UserNotifications/UserNotifications.h>#endif
    • Fill in the following code in the AppDelegate.h file, where the Appkey, channel, and isproduction fill in their
static NSString *appKey = @"";     //填写appkeystatic NSString *channel = @"";    //填写channel   一般为nilstatic BOOL isProduction = false;  //填写isProdurion  平时测试时为false ,生产时填写true

    • Add the following code to the APPDELEGATE.M Didfinishlaunchingwithoptions method
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{if ([[ Uidevice currentdevice].systemversion Floatvalue] >= 10.0) {#ifdef Nsfoundationversionnumber_ios_9_x_max JPUSHRegi     sterentity * entity = [[Jpushregisterentity alloc] init]; Entity.types = unauthorizationoptionalert| unauthorizationoptionbadge|     Unauthorizationoptionsound; [Jpushservice registerforremotenotificationconfig:entity delegate:self]; #endif} else if ([[Uidevice CurrentDevice]. Systemversion Floatvalue] >= 8.0) {[Jpushservice registerforremotenotificationtypes: (Uiusernotificationtypebadge                                                      |                                                      Uiusernotificationtypesound |  Uiusernotificationtypealert) Categories:nil]; } else {
This is a system that supports iOS8 before it can be deleted [Jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge | Uiremotenotificationtypesound | Uiremotenotificationtypealert) Categories:nil]; } [Jpushservice setupwithoption:launchoptions appkey:appkey Channel:channel Apsforproduction:ispro Duction];}
  
    • In the APPDELEGATE.M Didregisterforremotenotificationswithdevicetoken method, add the [Jpushservice Registerdevicetoken: Devicetoken]; As shown below
- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {  [JPUSHService registerDeviceToken:deviceToken];}
    • in order to receive push-click access to the app, you need to add [[Nsnotificationcenter] inside the APPDELEGATE.M didreceiveremotenotification method. Defaultcenter] Postnotificationname:kjpfdidreceiveremotenotification Object:userinfo] method, Note: There is a need to add one of the two methods in the previous one is IOS7 iOS7 that is later, if APPDELEGATE.M does not have this two methods to directly copy the two methods, the IOS10 device can use the Jpush provided by the two methods; as shown below
-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {//Get APNs Standard information content [[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];} IOS support-(void) Jpushnotificationcenter: (unusernotificationcenter *) Center willpresentnotification: ( Unnotification *) notification Withcompletionhandler: (void (^) (Nsinteger)) Completionhandler {//Required nsdictionary  * UserInfo = Notification.request.content.userInfo; if ([Notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice    Handleremotenotification:userinfo]; [[NsnotificationceNter Defaultcenter] Postnotificationname:kjpfdidreceiveremotenotification Object:userinfo]; } completionhandler (Unnotificationpresentationoptionalert); Need to execute this method, choose whether to remind the user, there are badge, sound, alert three types can choose to set}//IOS support-(void) Jpushnotificationcenter: ( Unusernotificationcenter *) Center didreceivenotificationresponse: (unnotificationresponse *) response Withcompletionhandler: (void (^) ()) Completionhandler {//Required nsdictionary * userInfo = Response.notification.reque  St.content.userInfo; if ([Response.notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice    Handleremotenotification:userinfo];  [[Nsnotificationcenter Defaultcenter] postnotificationname:kjpfdidreceiveremotenotification Object:userInfo];  } completionhandler (); The system requires that this method be executed}  

These steps git above, but the next is the chicken soup!!!
Open the Push notifications! in Xcode

2)

3)

And then in the JS code through the following listening callback to get notifications, it is best to listen to the project entry file

var { NativeAppEventEmitter } = require(‘react-native‘);componentDidMount (){  var subscription = NativeAppEventEmitter.addListener(    ‘ReceiveNotification‘,    (notification) => console.log(notification)  );
}...// 千万不要忘记忘记取消订阅, 通常在componentWillUnmount函数中实现。subscription.remove();

In the react native configuration three or four times, the configuration is not difficult, special pick the Aurora git on the instructions plus my configuration process of stepping on the pit, for your reference, if there is any incorrect place to hope that everyone in time, thank you



React Native's Aurora push jpush-react-native hand Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.