iOS-JPush 3.0 版本相关问题<Background modes>
来源:互联网 发布:武汉软件新城怎么样 编辑:程序博客网 时间:2024/06/07 00:03
写在前面:
请先使用pod或者官网下载,导入JPushSDK。
安装导入过程请参照JPush官网开发文档。
App内部操作:
注册JPush
在AppDelegate didFinishLaunchingWithOptions 这个方法里面注册JPush。
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { // 可以添加自定义categories // NSSet<UNNotificationCategory *> *categories for iOS10 or later // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9 } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; BOOL isProduction = YES;#if DEBUG isProduction = NO;//开启开发模式。#endif [JPUSHService setupWithOption:launchOptions appKey:appKey channel:nil apsForProduction:isProduction];
注册返回
#pragma mark - 注册返回- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ [JPUSHService registerDeviceToken:deviceToken];}
适配iOS10
需要添加如下代码:
需要NSFoundationVersionNumber_iOS_9_x_Max来进行判断
需要导入UserNotifications.framework
#ifdef NSFoundationVersionNumber_iOS_9_x_Max// iOS 10 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]; //这里执行点击通知的跳转方法 DLog(@"iOS10 收到前台通知:") } completionHandler(UNNotificationPresentationOptionBadge); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置}// iOS 10 Support- (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]; //这里执行点击通知的跳转方法 DLog(@"iOS10 收到远程通知:"); } completionHandler(); // 系统要求执行这个方法}#endif
需要在AppDelegate头部加上如下代码:
// iOS10注册APNs所需头文件#ifdef NSFoundationVersionNumber_iOS_9_x_Max#import <UserNotifications/UserNotifications.h>#endif
消息推送点击
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ [JPUSHService handleRemoteNotification:userInfo]; //这下面执行的,是对接收到的aps,进行必要处理 [self gt_application:application didReceiveRemoteNotification:userInfo];}// 收到远程推送通知时- (void)gt_application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSDictionary *aps = [userInfo valueForKey:@"aps"]; NSString *content = [aps valueForKey:@"alert"]; if (application.applicationState == UIApplicationStateInactive){ //启动APP或者换醒APP,以及相关跳转 }}
以上基本就已经完成了对JPush的配置。
以下是必须要注意的问题
注意
1.如果你的应用开启了BackGround Modes 如图:
第一个API是后台获取(Background Fetch),该API允许开发者在一个周期间隔后进行特定的动作,如获取网络内容、更新程序界面等等。第二个API是远程通知 (Remote Notification),它是一个新特性,它在当新事件发生时利用推送通知(Push Notifications)去告知程序。这两个新特性都是在后台进行的,这样更加有利于多任务执行。
那么你在AppDelegate里面实现的如下方法
将不再执行
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
s
而是要实现:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{ [JPUSHService handleRemoteNotification:userInfo]; //对aps的处理,并且要执行回调,刷新后台状态。 completionHandler(UIBackgroundFetchResultNewData);}
阅读全文
0 0
- iOS-JPush 3.0 版本相关问题<Background modes>
- 笔记:ios background modes
- Background Modes in iOS Tutorial
- Background Modes in iOS Tutorial
- Background Modes in iOS Tutorial
- Background Modes in iOS Tutorial
- Background Modes in iOS Tutorial
- IOS 6 之后 Required background modes
- Required background modes
- jpush相关
- JPush相关
- background-size属性相关问题
- JPush相关总结
- ios jpush notification
- iOS JPush极光推送
- iOS JPush简易使用
- Required background modes [info.plist 配置后台运行模式]
- Hadoop版本相关问题
- Android提醒微技巧Dialog、Toast和Snackbar
- 离散题目6
- 【转】Makefile文件名处理函数
- Vue入门之组件化开发
- 操作系统(一)
- iOS-JPush 3.0 版本相关问题<Background modes>
- 什么是异常,异常的分类?
- js中用构造器创建对象与字面量创建对象的区别
- 线性回归——最小二乘法
- 开始Python学习
- JQuery上传插件Uploadify的使用
- Vue实例详解与生命周期
- 先来简单介绍一下Block_转发自马在路上大神
- vue移动端地区选择练习1