极光推送android 环境,React Native 极光推送服务iOS与安卓环境配置

首先cd到项目的跟路径下面添加极光推送的库

npm install jcore-react-native --save 如图

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

4920F336-0AB9-4AA2-88E0-6A7A5074F4E8.png

在执行 npm install jpush-react-native --save 如图

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

5C742718-3507-4EF9-9EFD-B55F58583807.png

再去把这些库添加到项目里,执行 react-native link 导入成功

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

0FAC3292-F320-4439-AAC6-3EC3945ACD90.png

ios 的配置:

在 iOS 工程 target 的 Build Phases->Link Binary with Libraries 中加入如下库:如下图

libz.tbd

CoreTelephony.framework

Security.framework

CFNetwork.framework

CoreFoundation.framework

SystemConfiguration.framework

Foundation.framework

UIKit.framework

UserNotifications.framework

libresolv.tbd

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

12DEC172-78B8-407D-A1C8-05191CBB0076.png

打开项目中的AppDelegate 文件,引入两个文件名

import

import ,

并且定义三个参数

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

2D171439-BB81-46D6-8138-F496417671C2.png

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

{

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

//可以添加自定义categories

[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

UIUserNotificationTypeSound |

UIUserNotificationTypeAlert)

categories:nil];

} else {

//iOS 8以前 categories 必须为nil

[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)

categories:nil];

}

[JPUSHService setupWithOption:launchOptions appKey:appKey

channel:channel apsForProduction:isProduction];

NSURL *jsCodeLocation;

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation

moduleName:@"ts"

initialProperties:nil

launchOptions:launchOptions];

rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

UIViewController *rootViewController = [UIViewController new];

rootViewController.view = rootView;

self.window.rootViewController = rootViewController;

[self.window makeKeyAndVisible];

return YES;

}

//添加这个方法,将设备token传给极光的服务器

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

[JPUSHService registerDeviceToken:deviceToken];

}

//取得APNS推送过来的消息

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];

}

添加如下几个方法

- (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); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置

}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

// Required

NSDictionary * userInfo = response.notification.request.content.userInfo;

if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {

[JPUSHService handleRemoteNotification:userInfo];

[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];

}

completionHandler();// 系统要求执行这个方法

}

//iOS 7 Remote Notification

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

[[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo];

}

代码写完后,配置Info.plist文件

设置ATS权限 App Transport Security Settings的 Allow Arbitrary Loads为YES Exception Domains下的jpush.cn下的NSExceptionAllowsInsecureHTTPLoads为YES 和NSIncludesSubdomains为YES

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

688C1F21-D227-44B7-959F-1ECB27B0585F.png

打开推送

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

18C18ACF-4459-43AA-824B-0060E0601D3A.png

打开选择配置证书

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

092CC34C-EA73-4892-BCD6-5C1E53FE3F82.png

证书的配置

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

70556BC8-D831-427E-9906-3A8576C90D6A.png

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

F7DFAAA7-1BE7-449B-A728-3AE4D57DA36A.png

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

D307753D-1C77-444D-B0EE-CA3A8F37A94C.png

这里就配置完ios的配置了

然后看下代码的实现

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

0B8024FA-4A14-4241-B882-FE518F9D3290.png

这样就可以推送了。

安卓的配置

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

94CF55BE-E0A9-4824-A112-D38D87E80911.png

include ':jpush-react-native',':jcore-react-native'

project(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')

project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

Pasted Graphic.png

打开app文件下的build.gradle

manifestPlaceholders=[ JPUSH_APPKEY: "946df2fa1542693f71161217”,//自己的申请的key APP_CHANNEL: "应用宝" //应用渠道号,默认就好]

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

5FCA3DB5-B30A-4FBF-A6E1-14A8BC92C206.png

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

21F0F84C-FF6B-4A14-BC4F-5604E6386635.png

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

41608E83-6678-4488-AC72-7232FBA8F33A.png

4d215d54f984?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

6F99A996-70AC-46B3-A7A1-70C667C19D2A.png

配置完成后,在同步,然后就可以正常推送了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值