极光推送(二):自定义推送消息
来源:互联网 发布:淘宝卖家威胁要上门 编辑:程序博客网 时间:2024/05/21 10:57
上一篇文章介绍了极光推送里面通知的相关知识,下面我们直接进入主题,介绍一下极光推送里面自定义推送消息。
(1)首先,搞清楚极光里面通知和自定义推送消息之间的区别
通知 是无论在设备在前台还是后台,都可以接收到的。
自定义推送消息 是只能在前台,并且处于当前实现自定义消息的页面,必须满足这两点才可以接收到的。
(2)自定义推送消息的代码实现
1,首先在需要接收自定义消息的控制器导入头文件
#import"JPUSHService.h"
2,使用KVO模式进行监测
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter *defaultCenter = [NSNotificationCenterdefaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notificationuserInfo];
//content为自定义的消息内容 extras为可选设置里面的附加字段
NSString *title = [userInfovalueForKey:@"title"];
NSString *content = [userInfovalueForKey:@"content"];
NSDictionary *extra = [userInfovalueForKey:@"extras"];
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"极光自定义消息内容提示"message:content delegate:nilcancelButtonTitle:@"确定"otherButton Titles:nil,nil];
[alert show];
NSString *currentContent = [NSString
stringWithFormat:
@"收到自定义消息:%@\ntitle:%@\ncontent:%@\nextra:%@\n",
[NSDateFormatterlocalizedStringFromDate:[NSDatedate]
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterMediumStyle],
title, content, extra];
NSLog(@"%@", currentContent);
}
3,最后再释放掉相关对象
- (void)dealloc
{
NSNotificationCenter *defaultCenter = [NSNotificationCenterdefaultCenter];
[defaultCenter removeObserver:self
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
(3)最后再极光后台发送自定义推送消息,即可收到我们所需要的内容。
- 极光推送(二):自定义推送消息
- 极光推送(自定义消息通知)
- 极光推送—自定义消息
- Android极光推送自定义消息
- 极光推送(接收后台消息和自定义消息)
- iOS极光推送(接收后台消息和自定义消息)
- android消息推送---JPush(极光推送)
- 极光推送(JPush)通知与自定义消息的区别
- Android 极光推送获取自定义消息
- iOS极光推送之自定义消息
- iOS 极光推送接收自定义消息
- 极光推送自定义消息提示铃声
- Android消息推送,极光推送
- 极光推送,自定义对单个安卓手机推送消息
- Android 使用极光推送自定义消息推送效果
- 极光推送开发(二)
- ios 推送消息 极光推送/百度推送
- IOS 极光推送消息
- org.apache.hadoop.fs.ChecksumException:Checksum error
- hdu5119 DP
- eclipse突然运行变慢
- Sitemesh3 的使用及配置
- android中carrier表示什么
- 极光推送(二):自定义推送消息
- 基础排序算法
- SpringMVC 解决IE8浏览器把返回报文格式application/json当文件下载的问题
- 骨牌铺方格
- vim笔记
- iOS安全攻防-键盘安全
- APM(应用性能管理)漏斗分析使用
- 面向对象程序设计上机练习九(对象指针)
- android系统镜像:boot.img kernel.img ramdisk.img system.img userdata.img cache.img recovery.img