自定义推送消息
来源:互联网 发布:修改ssh 默认端口 编辑:程序博客网 时间:2024/06/05 10:11
版权声明:本文为博主原创文章,未经博主允许不得转载。
上一篇文章介绍了极光推送里面通知的相关知识,下面我们直接进入主题,介绍一下极光推送里面自定义推送消息。
(1)首先,搞清楚极光里面通知和自定义推送消息之间的区别
通知 是无论在设备在前台还是后台,都可以接收到的。
自定义推送消息 是只能在前台,并且处于当前实现自定义消息的页面,必须满足这两点才可以接收到的。
(2)自定义推送消息的代码实现
1,首先在需要接收自定义消息的控制器导入头文件
#import"JPUSHService.h"
2,使用KVO模式进行监测
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
//content为自定义的消息内容 extras为可选设置里面的附加字段
NSString *title = [userInfo valueForKey:@"title"];
NSString *content = [userInfo valueForKey:@"content"];
NSDictionary *extra = [userInfo valueForKey:@"extras"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"极光自定义消息内容提示" message:content delegate:nilcancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
NSString *currentContent = [NSString
stringWithFormat:
@"收到自定义消息:%@\ntitle:%@\ncontent:%@\nextra:%@\n",
[NSDateFormatter localizedStringFromDate:[NSDate date]
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterMediumStyle],
title, content, extra];
NSLog(@"%@", currentContent);
}
3,最后再释放掉相关对象
- (void)dealloc
{
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter removeObserver:self
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
(3)最后再极光后台发送自定义推送消息,即可收到我们所需要的内容。
- Android自定义消息推送
- 自定义消息推送
- 自定义推送消息
- 极光推送(二):自定义推送消息
- 极光推送—自定义消息
- Android极光推送自定义消息
- Android- Notification消息推送和自定义消息推送
- 微信自定义推送模版消息
- Android之极光推送发送自定义消息
- Android 极光推送获取自定义消息
- iOS极光推送之自定义消息
- 关于IOS自定义推送消息铃声
- iOS 极光推送接收自定义消息
- 极光推送(自定义消息通知)
- 极光推送自定义消息提示铃声
- Android之极光推送发送自定义消息
- 极光推送,自定义对单个安卓手机推送消息
- Android 使用极光推送自定义消息推送效果
- Selenium下各浏览器driver的配置 火狐浏览器 System.setProperty("webdriver.firefox.bin","C:\\ProgramFiles\\MozillaFi
- 做到这些_才算是顶级程序员
- SVG进阶教程全攻略
- TLS/SSL 协议详解(1) 前言
- MyEclipse2017下创建Spring项目
- 自定义推送消息
- Android完全禁止第三方软件安装的方法
- Tensorflow 激励函数 Activation Function
- css样式
- hdu5001 Walk (概率dp)
- [RK3288][Android6.0] 有线耳机驱动小结
- 微信小程序的探讨
- android开发——Android开发中的47个小知识
- 两个LinearLayout实现简单的菜单增加和删除