ios 开发之 -- 极光推送,发送自定义消息,进入制定页面
在进行极光推送时候,发现版本有所更新,以前截取didfinish入口方法里面的launchOptions,获取一个本地的通知内容,进行本地展示不可用了,通过查询官方文档和网上的资料才发现,方法改变了,具体方法如下(只针对怎样定义消息):
1,功能说明
只有在前端运行的时候才能收到自定义消息的推送。
从jpush服务器获取用户推送的自定义消息内容和标题以及附加字段等。
2,实现方法
获取iOS的推送内容需要在delegate类中注册通知并实现回调方法。
在方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions 加入下面的代码:
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
实现回调方法:
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary * userInfo = [notification userInfo];
NSString *content = [userInfo valueForKey:@"content"];
NSDictionary *extras = [userInfo valueForKey:@"extras"];
NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //服务端传递的Extras附加字段,key是自己定义的
}
参数描述:
content:获取推送的内容
extras:获取用户自定义参数
customizeField1:根据自定义key获取自定义的value
更多实现参考 SDK下载压缩包中的 demo。
3,跳转目标页面方法的实现,在第二步的回调方法里面插入如下方法:
[self getPushMessageAtStateActive:userInfo];
方法代码:
#pragma mark -- 程序运行时收到通知
-(void)getPushMessageAtStateActive:(NSDictionary *)pushMessageDic{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
message:[pushMessageDic objectForKey:@"content"]
preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"查看"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { UIViewController *targetVC = [self topVC:[UIApplication sharedApplication].keyWindow.rootViewController]; [targetVC.navigationController pushViewController:[[AuthenticationViewController alloc] init] animated:YES];
}]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:confirmAction];
[alertController addAction:cancelAction];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil]; }
- (UIViewController *)topVC:(UIViewController *)rootViewController{
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tab = (UITabBarController *)rootViewController;
return [self topVC:tab.selectedViewController];
}else if ([rootViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *navc = (UINavigationController *)rootViewController;
return [self topVC:navc.visibleViewController];
}else if (rootViewController.presentedViewController){
UIViewController *pre = (UIViewController *)rootViewController.presentedViewController;
return [self topVC:pre];
}else{
return rootViewController;
}
}
这样的话,就可以实现,点击弹出的alerview的确定按钮,进入指定的页面了!
--------------------------------------------------------------------------------------------------------------
上面说的是发送自定义消息的方法,这里来说下app在后台,或者不活跃状态时候的操作:
1,通知的三种形式:
typedef NS_OPTIONS(NSUInteger, UNNotificationPresentationOptions) {
UNNotificationPresentationOptionBadge = ( << ),
UNNotificationPresentationOptionSound = ( << ),
UNNotificationPresentationOptionAlert = ( << ),
}
2,在此方法里面实现:
// 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];
}else is
{
//本地通知
}
completionHandler(); // 系统要求执行这个方法
}
或者:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
NSLog(@"userinfo is %@",userInfo);
UIViewController *targetVC = [self topVC:[UIApplication sharedApplication].keyWindow.rootViewController];
targetVC.hidesBottomBarWhenPushed = YES;
[targetVC.navigationController pushViewController:[[AuthenticationViewController alloc] init] animated:YES];
completionHandler(UIBackgroundFetchResultNewData);
}
一个是系统的方法,一个是极光的方法,本地化创建一个alertview也是可以实现,也可以直接在系统方法里面,进行操作,比如跳转到指定页面之类的都可以的!
在目标页面的话,如果底下的tabbar没有隐藏的话,可添加如下代码(仅做参考,隐藏的方法有很多):
-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.tabBar.hidden = YES;
} -(void)viewWillDisappear:(BOOL)animated
{
self.tabBarController.tabBar.hidden = NO;
}
仅供参考,一些以官方文档为准!如果不正确的地方,欢迎指正!
附个极光的链接:
https://docs.jiguang.cn/jpush/client/iOS/ios_api/#api-ios
ios 开发之 -- 极光推送,发送自定义消息,进入制定页面的更多相关文章
- 李洪强iOS开发之极光推送JPush
李洪强iOS开发之极光推送JPush
- Android之极光推送发送自定义消息
Android端实现主要代码: <span style="font-size:14px;">import java.io.IOException; import jav ...
- 李洪强iOS之集成极光推送一iOS SDK概述
李洪强iOS之集成极光推送一iOS SDK概述 JPush iOS 从上图可以看出,JPush iOS Push 包括 2 个部分,APNs 推送(代理),与 JPush 应用内消息. 红色部分是 A ...
- 李洪强iOS之集成极光推送三iOS集成指南
李洪强iOS之集成极光推送三iOS集成指南 SDK说明 适用版本 本文匹配的 SDK版本:r2.1.5 以后.查看最近更新了解最新的SDK更新情况.使用Xcode 6及以上版本可以使用新版Push S ...
- 李洪强iOS之集成极光推送二iOS 证书 设置指南
李洪强iOS之集成极光推送二iOS 证书 设置指南 创建应用程序ID 登陆 iOS Dev Center 选择进入iOS Provisioning Portal. 在 iOS Provisioning ...
- iOS开发:创建推送开发证书和生产证书,以及往极光推送官网上传证书的步骤方法
在极光官网上面上传应用的极光推送证书的实质其实就是上传导出的p12文件,在极光推送应用管理里面,需要上传两个p12文件,一个是生产证书,一个是开发证书 ,缺一不可,具体如下所示: 在开发者账号里面创建 ...
- 【原】iOS学习之极光推送
一.极光推送工程端 1.下载SDK 极光推送是一个推送消息的第三方,SDK下载:https://www.jpush.cn/common/products 集成压缩包内容:包名为JPush-iOS-SD ...
- iOS开发之远程推送
说到远程推送,应该用的也挺多的,今天就基于SEA的云推送服务,做一个推送的小demo,来了解一下iOS中的远程推送是怎么一回事儿,首先你得有苹果的开发者账号,好咸蛋也差不多了,主要内容走起. 一.准备 ...
- [iOS]iPhone利用<极光推送>实现远程推送
准备: 1. 一个Xcode工程 2. 开发者账号 3. 真机 (重要,模拟器无法进行远程推送,因为模拟器没有UDID) 第一步:绑定工程的Bundle Identifer 首先当然要登录https: ...
随机推荐
- CRC文件解压缩问题
CRC问题一般有三种可能1.你的硬盘出现坏道2.你的硬盘数据线受损3.还可能是主板和内存的问题 硬盘坏道的表现硬盘使用久了就可能出现各种各样的问题,而硬盘“坏道”便是这其中最常见的问题.硬盘出现坏道除 ...
- RFID编码
信号编码系统包括信源编码和信道编码两大类,器作用是把要传输的信息尽可能的与传输信道相匹配,并提供对信息的某种保护以防止信息受到干扰.信源编码与信源译码的目的是提高信息传输的有效性以及完成模数转换等:信 ...
- 停掉一台服务器,Nginx响应慢(转载)
测试发现的问题及解决办法 1.当后端两台IIS应用服务器都正常时,访问速度非常快,查看日志,原来一个请求,是后端两台服务器同时响应的; 2.为了模仿故障测试,停掉一台IIS应用服务器,这时再访问,请求 ...
- unity, access material
MeshRenderer meshRenderer=gameObject.GetComponent<MeshRenderer>(); if(meshRende ...
- Entity Framework底层操作封装V2版本号(2)
这个类是真正的数据库操作类.上面的那个类仅仅是调用了这个封装类的方法进行的操作 using System; using System.Collections.Generic; using System ...
- 穷人的语义处理工具箱之中的一个:语义版Jaccard
/* 版权声明:能够随意转载,转载时请标明文章原始出处和作者信息 .*/ author: 张俊林 |为什么我们是ML界的穷人 假设对工业界里的机器学习(ML)从业者进行阶级划分的话,划线标准不是你用的 ...
- centos 搭建nginx
yum install wget yum install gcc-c++ yum -y install pcre prec-devel yum -y install zlib zlib-devel y ...
- Spring Oauth2 with JWT Sample
https://www.javacodegeeks.com/2016/04/spring-oauth2-jwt-sample.html ******************************** ...
- sqlmap如何跑base64加密了的注入点
其实http://www.cnblogs.com/xishaonian/p/6276799.html这个就是一个案例了. 但是不得不重写一篇文章来记载.因为这是一个姿势.很好的姿势. 保存为xisha ...
- [转][Python基础]Python中的Lambda表达式
引用自:http://www.cnblogs.com/evening/archive/2012/03/29/2423554.html 在学习python的过程中,lambda的语法时常会使人感到困惑, ...