融云项目经验总结-头像和昵称显示/badge显示

1.  头像和昵称展示

融云为我们提供了两种头像和昵称显示方式

1). 头像和昵称随着消息一起发送给对方,这样的方式缺点是:当对方没有回复消息时,用户回话界面不能够显示对方的头像和昵称

代码: 在delegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法中添加如下代码,

    [[RCIM sharedRCIM] setCurrentUserInfo:(RCUserInfo *)];

    [RCIMsharedRCIM].enableMessageAttachUserInfo =YES;


2). 在程序需要显示头像和昵称的时候,将头像和昵称发送给融云服务器

同样在delegate中,实现融云的代理方法

// 是否将用户信息和群组信息在本地持久化存储,默认值为NO
    [RCIM sharedRCIM].enablePersistentUserInfoCache = YES;

    [[RCIMsharedRCIM] setUserInfoDataSource:self];

- (void)getUserInfoWithUserId:(NSString *)userId

                   completion:(void (^)(RCUserInfo *userInfo))completion

{

    if ([userIdisEqualToString:@"1"]) {

        return completion([[RCUserInfoalloc] initWithUserId:userIdname:@"11"portrait:@"http://pic28.nipic.com/20130424/11588775_115415688157_2.jpg"]);


    }else

    {

        return completion([[RCUserInfoalloc] initWithUserId:userIdname:@"01"portrait:@"http://pic32.nipic.com/20130827/12906030_123121414000_2.png"]);


    }

}

2. 当收到消息时,实现badge的显示,如果想要app icon显示角标,那只要在下面的方法中实现即可

    //设置消息提示

    [[RCIMsharedRCIM] 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];
        }
     
            });


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值