极光推送Jpush-react-native在ios中的详细配置 本人亲测
2018-03-14 17:17
519 查看
IOS极光推送配置:
安装
1.自动配置部分(以下命令均在你的React Native Project目录下运行)
根据提示填写appKey 填写包名
自动配置操作会自动插入Native代码 检查自动配置代码,在 Native 中需要添加的代码:
在 AppDelegate.m 文件中 填写如下代码,这里的的 appkey(极光官网上创建应用时自动生成)、channel(一般为cli)、和 isProduction (false为测试环境true为开发环境)填写自己的
在 AppDelegate.m didRegisterForRemoteNotificationsWithDeviceToken 方法中添加 [JPUSHService registerDeviceToken:deviceToken]; 如下所示
为了在收到推送点击进入应用能够获取该条推送内容需要在 AppDelegate.m didReceiveRemoteNotification 方法里面添加 [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo] 方法,注意:这里需要在两个方法里面加一个是 iOS7 以前的一个是 iOS7 即以后的,如果 AppDelegate.m 没有这个两个方法则直接复制这两个方法,在 iOS10 的设备则可以使用 JPush 提供的两个方法;如下所示
2.手动操作部分(自动配置后,部分操作需要手动修改)
在手动配置之前需在TARGETS-> BUILD Phases -> LinkBinary with Libraries中添加 AdSupport.framework 库 (有时会添加不上去需多添加几遍就ok了)
iOS 手动操作部分 (3 个步骤)
● 在 iOS 工程中设置 TARGETS-> BUILD Phases -> LinkBinary with Libraries 找到 UserNotifications.framework 把 status 设为 optional
● 在 iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下路径
● 在 xcode8 之后需要点开推送选项: TARGETS -> Capabilities -> Push Notification 设为 on 状态
配置证书http://blog.csdn.net/liu__520/article/details/53133497
建议配置证书观看极光官网的教学视频
https://community.jiguang.cn/t/jpush-ios-sdk/4247
在配置好证书后 需要将极光上ios中的Bundle ID 复制到 Xcode中General下 Bundle identifier 中
在General->Signing 中Team选择的apple ID 必须与你注册证书的apple ID 一致,且保证不报错,接下来就可以在极光官网上发送推送任务了
安装
npm install --save jpush-react-native npm install --save jcore-react-native
1.自动配置部分(以下命令均在你的React Native Project目录下运行)
react-native link
根据提示填写appKey 填写包名
自动配置操作会自动插入Native代码 检查自动配置代码,在 Native 中需要添加的代码:
在 AppDelegate.m 文件中 填写如下代码,这里的的 appkey(极光官网上创建应用时自动生成)、channel(一般为cli)、和 isProduction (false为测试环境true为开发环境)填写自己的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound; [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; [JPUSHService setupWithOption:launchOptions appKey:appkey channel:nil apsForProduction:isProduction]; }
在 AppDelegate.m didRegisterForRemoteNotificationsWithDeviceToken 方法中添加 [JPUSHService registerDeviceToken:deviceToken]; 如下所示
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [JPUSHService registerDeviceToken:deviceToken]; }
为了在收到推送点击进入应用能够获取该条推送内容需要在 AppDelegate.m didReceiveRemoteNotification 方法里面添加 [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo] 方法,注意:这里需要在两个方法里面加一个是 iOS7 以前的一个是 iOS7 即以后的,如果 AppDelegate.m 没有这个两个方法则直接复制这两个方法,在 iOS10 的设备则可以使用 JPush 提供的两个方法;如下所示
- (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]; } // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler { // Required NSDictionary * userInfo = notification.request.content.userInfo; [JPUSHService handleRemoteNotification:userInfo]; [[NSNotificationCenter defaultCenter] postNotificationName:kJPFDidReceiveRemoteNotification object:userInfo]; completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置 } // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { NSDictionary * userInfo = response.notification.request.content.userInfo; [JPUSHService handleRemoteNotification:userInfo]; [[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotification object:userInfo]; completionHandler(); }
2.手动操作部分(自动配置后,部分操作需要手动修改)
在手动配置之前需在TARGETS-> BUILD Phases -> LinkBinary with Libraries中添加 AdSupport.framework 库 (有时会添加不上去需多添加几遍就ok了)
iOS 手动操作部分 (3 个步骤)
● 在 iOS 工程中设置 TARGETS-> BUILD Phases -> LinkBinary with Libraries 找到 UserNotifications.framework 把 status 设为 optional
● 在 iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下路径
$(SRCROOT)/../node_modules/jpush-react-native/ios/RCTJPushModule
● 在 xcode8 之后需要点开推送选项: TARGETS -> Capabilities -> Push Notification 设为 on 状态
注意
必须是真机测试 虚拟就不支持APns配置证书http://blog.csdn.net/liu__520/article/details/53133497
建议配置证书观看极光官网的教学视频
https://community.jiguang.cn/t/jpush-ios-sdk/4247
在配置好证书后 需要将极光上ios中的Bundle ID 复制到 Xcode中General下 Bundle identifier 中
在General->Signing 中Team选择的apple ID 必须与你注册证书的apple ID 一致,且保证不报错,接下来就可以在极光官网上发送推送任务了
相关文章推荐
- react-native 中配置极光推送 Android关键详细的说明与截图代码 找不到类Bundle/JPushInterface
- 原生Android项目中集成react-native以及jpush-react-native(极光推送)
- react-native 集成极光推送jpush-react-native时的小问题
- React-Native极光推送全程教程android和ios
- react native极光推送全程教程android和ios
- React-Native极光推送android和ios证书申请
- react-native Android极光推送配置
- iOS极光推送 --> JPush步骤
- 史上最详细Windows版本搭建安装React Native环境配置
- react-native 极光推送android篇
- iOS 远程推送的详细配置
- React-Native 工程添加推送功能 (iOS 篇)
- RN IOS极光推送配置
- ios React Native 入门环境配置
- react-native学习笔记--史上最详细Windows版本搭建安装React Native环境配置
- iOS 远程推送的详细配置
- iOS-React Native调试配置
- iOS ReactNative环境配置搭建安装React-Native遇到的问题
- React-Native 工程添加推送功能 (iOS 篇)