IOS 通知(实现及时聊天接受消息的现实)
2015-05-06 13:04
281 查看
为什么要用通知?
传递一个变化的数值。
例子
传递一个变化的数值。
例子
//接受消息 -(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message{ NSLog(@"%@说:%@",message.from,message.body); [[NSNotificationCenter defaultCenter]postNotificationName:@"didREceiveMessage" object:nil userInfo:@{@"message":message}]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //设置广播内容 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: message.body, @"ThemeName", nil]; //将内容封装到广播中 给ios系统发送广播 [nc postNotificationName:@"getmessage" object:self userInfo:dict];// getmessage频道 } NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; // 成为听众一旦有广播就来调用self recvBcast:函数 [nc addObserver:self selector:@selector(recvBcast:) name:@"getmessage" object:nil]; - (void) recvBcast:(NSNotification *)notify { static int index; NSLog(@"recv bcast %d", index++); NSDictionary *dict = [notify userInfo]; NSString *getmessageTemp = [dict objectForKey:@"ThemeName"]; NSLog(@"name的值:%@",getmessageTemp); [self.meassage addObject:getmessageTemp]; [self.tView reloadData]; }
相关文章推荐
- ios学习--为iOS5设计消息通知的实现方法
- (素材源码)猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- (素材源码)猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- 猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- 猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- iOS项目开发实战——实现苹果本地消息通知推送服务
- iOS中QQ聊天界面发送消息及表情键盘的实现
- AJ学IOS(18)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- iOS开发:消息中心(广播通知)
- IOS开发之实现App消息推送
- IOS -- XMPPFramework 即时聊天(3:XMPPFramework 实现连接服务器)
- IOS 新消息通知提示-声音、震动
- ios消息推送机制原理与实现
- iOS开发如何实现消息推送机制
- 推送通知iOS客户端编写实现及推送服务器端编写
- Android之消息推送聊天实现
- iOS消息推送机制的实现
- iOS消息推送机制的实现
- iOS开发如何实现消息推送机制
- ios消息推送机制原理与实现