融云项目经验总结-头像和昵称显示/badge显示(转)
2017-02-20 22:57
211 查看
1. 头像和昵称展示
融云为我们提供了两种头像和昵称显示方式
1). 头像和昵称随着消息一起发送给对方,这样的方式缺点是:当对方没有回复消息时,用户回话界面不能够显示对方的头像和昵称
代码: 在delegate的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中添加如下代码,
[[RCIM sharedRCIM] setCurrentUserInfo:(RCUserInfo *)];
[RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
2). 在程序需要显示头像和昵称的时候,将头像和昵称发送给融云服务器
同样在delegate中,实现融云的代理方法
[[RCIM sharedRCIM] setUserInfoDataSource:self];
- (void)getUserInfoWithUserId:(NSString *)userId
completion:(void (^)(RCUserInfo *userInfo))completion
{
if ([userId isEqualToString:@"1"]) {
return completion([[RCUserInfo alloc] initWithUserId:userId name:@"11"portrait:@"http://pic28.nipic.com/20130424/11588775_115415688157_2.jpg"]);
}else
{
return completion([[RCUserInfo alloc] initWithUserId:userId name:@"01"portrait:@"http://pic32.nipic.com/20130827/12906030_123121414000_2.png"]);
}
}
2. 当收到消息时,实现badge的显示,如果想要app icon显示角标,那只要在下面的方法中实现即可
// 设置消息提示
[[RCIM sharedRCIM] setReceiveMessageDelegate:self];
_view=[[RCMessageBubbleTipView alloc]initWithParentView:self.tabbar.tabBar alignment:RC_MESSAGE_BUBBLE_TIP_VIEW_ALIGNMENT_BOTTOM_RIGHT];
//收到消息的监听
- (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left
{
dispatch_sync(dispatch_get_main_queue(), ^{
_view.bubbleTipPositionAdjustment=CGPointMake(0,0);
_view.frameToPositionInRelationWith=CGRectMake(0, 0, 100, 10)
_view.bubbleTipText =[NSString stringWithFormat:@"%ld",(long)[[RCIMClient sharedRCIMClient]getUnreadCount:ConversationType_PRIVATE targetId:@"12"]];
@discussion 如果为NO,会显示红点,不显示具体数字。
*/
@property(nonatomic) BOOL isShowNotificationNumber;
NSInteger unread=[[RCIMClient sharedRCIMClient]getTotalUnreadCount];
[self.tabbar.tabBar addSubview:_view];
if ([_view.bubbleTipText isEqualToString:@"0"]) {
_view.hidden=YES;
}
if (unread>=100) {
_view.bubbleTipText=@"99+";
_view.bubbleTipTextFont=[UIFont systemFontOfSize:12];
}
});
}
融云为我们提供了两种头像和昵称显示方式
1). 头像和昵称随着消息一起发送给对方,这样的方式缺点是:当对方没有回复消息时,用户回话界面不能够显示对方的头像和昵称
代码: 在delegate的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中添加如下代码,
[[RCIM sharedRCIM] setCurrentUserInfo:(RCUserInfo *)];
[RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
2). 在程序需要显示头像和昵称的时候,将头像和昵称发送给融云服务器
同样在delegate中,实现融云的代理方法
[[RCIM sharedRCIM] setUserInfoDataSource:self];
- (void)getUserInfoWithUserId:(NSString *)userId
completion:(void (^)(RCUserInfo *userInfo))completion
{
if ([userId isEqualToString:@"1"]) {
return completion([[RCUserInfo alloc] initWithUserId:userId name:@"11"portrait:@"http://pic28.nipic.com/20130424/11588775_115415688157_2.jpg"]);
}else
{
return completion([[RCUserInfo alloc] initWithUserId:userId name:@"01"portrait:@"http://pic32.nipic.com/20130827/12906030_123121414000_2.png"]);
}
}
2. 当收到消息时,实现badge的显示,如果想要app icon显示角标,那只要在下面的方法中实现即可
// 设置消息提示
[[RCIM sharedRCIM] setReceiveMessageDelegate:self];
_view=[[RCMessageBubbleTipView alloc]initWithParentView:self.tabbar.tabBar alignment:RC_MESSAGE_BUBBLE_TIP_VIEW_ALIGNMENT_BOTTOM_RIGHT];
//收到消息的监听
- (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left
{
dispatch_sync(dispatch_get_main_queue(), ^{
_view.bubbleTipPositionAdjustment=CGPointMake(0,0);
_view.frameToPositionInRelationWith=CGRectMake(0, 0, 100, 10)
_view.bubbleTipText =[NSString stringWithFormat:@"%ld",(long)[[RCIMClient sharedRCIMClient]getUnreadCount:ConversationType_PRIVATE targetId:@"12"]];
@discussion 如果为NO,会显示红点,不显示具体数字。
*/
@property(nonatomic) BOOL isShowNotificationNumber;
NSInteger unread=[[RCIMClient sharedRCIMClient]getTotalUnreadCount];
[self.tabbar.tabBar addSubview:_view];
if ([_view.bubbleTipText isEqualToString:@"0"]) {
_view.hidden=YES;
}
if (unread>=100) {
_view.bubbleTipText=@"99+";
_view.bubbleTipTextFont=[UIFont systemFontOfSize:12];
}
});
}
相关文章推荐
- 融云项目经验总结-头像和昵称显示/badge显示
- 影响项目的因素及经验总结
- 项目技术经验总结二:系统多风格的实现
- 项目经验的零星总结
- [置顶]团队开发经验:如何带领一个项目团队并做好项目总结
- 由PPP项目总结的几点项目经验
- 项目管理经验总结
- 软件项目经理的心得和经验总结
- 大项目研发经验总结之摩西十戒
- PDA项目开发经验总结
- 团队开发经验:如何带领一个项目团队并做好项目总结
- 项目经验技术总结三:系统业务基础数据维护
- 项目经验教训总结
- 第一个项目(LIMS)管理经验阶段总结-测试版(待续)
- 南京华为项目经验总结(大方向)
- 项目技术经验总结一:asp.net+oracle部署,防火墙端口开设
- 异地开发项目合作做总结的经验
- 项目经理三年多来的一些心得和经验总结
- 团队开发经验:如何带领一个项目团队并做好项目总结 !!
- Yycom项目经验总结(ASP与JAVASCRIPT)