您的位置:首页 > 其它

融云项目经验总结-头像和昵称显示/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];

        }

     

            });

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: