使用融云SDK, 如何自定义好友消息。
融云sdk的集成方法可以访问 http://rongcloud.cn相关文档,下面介绍自定义好友消息的实现方法。
图1
图2
图1为自定义 viewController xo继承自 RCConversationListViewController 。 使用聚合的方式展示系统消息通知。
@interface SymtemViewController :RCConversationListViewController
@end
采用继承的方式,是为了重写点击cell的响应方式,接下来在.m 文件中重写父类的 onSelectedTableRow 方法。
//重载函数。
-(void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath
{
if (model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_NORMAL) {
}
// 自定义type
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_COLLECTION)
{
if (model.conversationType ==ConversationType_SYSTEM)
{
ChatListViewController *listVC = [[ChatListViewControlleralloc]init];
NSArray *array =@[[NSNumbernumberWithInt:ConversationType_SYSTEM]];
[listVC setDisplayConversationTypeArray:array];
[self.navigationControllerpushViewController:listVCanimated:YES];
}
}
//
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION)
{
}
//
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_PUBLIC_SERVICE)
{
NSLog(@” … SERVICE …”);
}
}
其中ChatListViewController为接下来要展示的好友的详细列表viewController。 继承自 RCConversationListViewController,在自定义cell之前先明确添加好友通知的几种情况。
其中
demo server 指 客户端服务器
RC server 指融云服务器
userID 指 当前用户ID
1 推荐好友。 如图2中sourceID_5。
当前只需要 demo server 向 RC server 发送好友推荐通知即可。
2 好友请求成功发送。 如图2中sourceID_6。
此时 demo server 需要调用两次接口,访问RC server两次。 第一次通知 userID 用户好友已发送。 第二次 向 sourceID_6 用户发送有一个好友请求。
3 对方同意你的好友请求。如图2中sourceID_7。
demo server 向 RC server 发送 userID 用户请求的状态。是第五条处理后发过来的结果。
4 收到好友请求。如图2中sourceID_8。
demo server 向 RC server 发送sourceID_8 向userID发送的好友请求。
5 处理好友请求。如图2中sourceID_9。
demo server 需要调用两次接口,访问RC server两次。 一次通知 userID 用户 结果。 另一次通知sourceID 用户操作结果。
如果不全,还可以通过修改发送内容,进行补充。
发送系统消息是通过调用如下API 来实现的。
发送系统消息 方法
说明:一个用户向一个或多个用户发送系统消息,会话类型为 SYSTEM。
方法名:/message/system/publish
调用频率:每秒钟限 100 次
签名方法:请参考 通用 API 接口签名规则
URL:https://api.cn.ronghub.com/message/system/publish.[format]
[format] 表示返回格式,可以为 json
或 xml
,注意不要带 [ ]。
HTTP 方法:POST
表单参数
名称 | 类型 | 说明 |
---|---|---|
fromUserId |
String | 发送人用户 Id。(必传) |
toUserId |
String | 接收用户Id,提供多个本参数可以实现向多用户发送系统消息,上限为 1000 人。(必传) |
objectName |
String | 消息类型,参考融云消息类型表.消息标志 ;可自定义消息类型。(必传) |
content |
String | 发送消息内容,参考融云消息类型表.示例说明 ;如果 objectName 为自定义消息类型,该参数可自定义格式。(必传) |
pushContent |
String | 定义显示的 Push 内容,如果为自定义消息,则为自定义消息显示的 Push 内容。(可选) |
pushData |
String | Push 通知附加的 payload 字段,字段名为 appData。(可选) |
其它不同的消息内空的区分是由objectName 和 content 来决定的。
好友通知objectName 固定为 @“RC:ContactNtf”。
content 内空实际上为一个字典 {“operation”:”Recommend”,”sourceUserId”:”5″,”targetUserId”:”1″,”message”:”haha”,”extra”:”hello extra”}
其它operation 对应的value值为操作内容。用于判断当前的通知是五种情况下下的一种。
当前sdk定义了三个已用宏
// 加好友请求。
#define ContactNotificationMessage_ContactOperationRequest @“Request”
// 同意好友请求。
#define ContactNotificationMessage_ContactOperationAcceptResponse @“AcceptResponse”
// 拒绝好友请求。
#define ContactNotificationMessage_ContactOperationRejectResponse @“RejectResponse”
// 推荐好友。
#define ContactNotificationMessage_ContactOperationRecommend @“Recommend”
// 加好友请求验证状态。
#define ContactNotificationMessage_ContactOperationRequestSent @“RequestSent”
需要注意一点
下面介绍自定义cell代码的实现。
在ChatListViewController.m 文件中
1 重写数据源的方法,设置好友通知消息为自定义类型
//
– (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource
{
for (int i=0; i<dataSource.count; i++) {
RCConversationModel *model =[dataSource objectAtIndex:i];
if (model.conversationType ==ConversationType_SYSTEM
|| [model.lastestMessageisMemberOfClass:RCContactNotificationMessage.class]) {
model.conversationModelType =RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION;
}
}
return dataSource;
}
2 重写cell高度及cell加载方法。
//
– (CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0f;
}
//
– (RCConversationBaseCell *)rcConversationListTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @”cellidentifier”;
RCConversationModel *model = self.conversationListDataSource[indexPath.row];
id obj= model.lastestMessage;
if (![obj isKindOfClass:RCContactNotificationMessage.class])
{
// todo 处理其它类型的系统消息
return nil;
}
FriendMessageCell *cell = [[FriendMessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
[cell setFriendMessage:model];
return cell;
}
3 重写消息监听方法。
#pragma mark – 收到消息监听
-(void)didReceiveMessageNotification:(NSNotification *)notification
{
__weak typeof(&*self) blockSelf_ =self;
//处理好友请求
RCMessage *message = notification.object;
if ([message.contentisMemberOfClass:[RCContactNotificationMessageclass]])
{
RCContactNotificationMessage *msg = (RCContactNotificationMessage *)message.content;//
BOOL isExist = NO;
// 监测请求是否己存在
for (RCConversationModel *modelin self.conversationListDataSource) {
id obj= model.lastestMessage;
if (![objisKindOfClass:RCContactNotificationMessage.class]) {
continue;
}
RCContactNotificationMessage *notiMessage = (RCContactNotificationMessage *)obj;
// 判断sourceId targetUserId 均相同。例: 我可以同时向多个userID发送好友请求
if ([msg.sourceUserIdisEqualToString:notiMessage.sourceUserId] && [msg.targetUserIdisEqualToString:notiMessage.targetUserId]) {
isExist = YES;
break;
}
}
if (isExist == YES)
{
[blockSelf_ refreshConversationTableViewIfNeeded];
}
else
{
// dic 存储用户信息,cell中使用. 用户信息从demo server 获得。
NSDictionary *dic = [NSDictionarydictionary];
RCConversationModel *customModel = [[RCConversationModelalloc]init];
customModel.conversationModelType =RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION;
customModel.extend = dic;
customModel.senderUserId = message.senderUserId;
customModel.lastestMessage = msg;
customModel.sentTime = message.sentTime;
customModel.targetId = message.targetId;
//刷新
[blockSelf_ refreshConversationTableViewWithConversationModel:customModel];
}
[blockSelf_ resetConversationListBackgroundViewIfNeeded];
}else{
[superdidReceiveMessageNotification:notification];
}
}
…
全部代码如下:
.h 文件
#import <UIKit/UIKit.h>
#import <RongIMKit/RongIMKit.h>
@interface ChatListViewController :RCConversationListViewController
@end
.m 文件
#import “ChatListViewController.h”
#import “constheader.h”
#import “FriendMessageCell.h”
@interface ChatListViewController()
@end
@implementation ChatListViewController
//
– (void)viewDidLoad
{
[superviewDidLoad];
self.conversationListTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
// override
//重载函数,onSelectedTableRow是选择会话列表之后的事件,该接口开放是为了便于您自定义跳转事件。在快速集成过程中,您只需要复制这段代码。
-(void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath
{
if (model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_NORMAL)
{
RCConversationViewController *conversationVC = [[RCConversationViewControlleralloc]init];
conversationVC.conversationType =model.conversationType;
conversationVC.targetId = model.targetId;
conversationVC.userName =model.conversationTitle;
conversationVC.title = model.conversationTitle;
conversationVC.hidesBottomBarWhenPushed =YES;
[self.navigationControllerpushViewController:conversationVCanimated:YES];
}
//
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_COLLECTION)
{
ChatListViewController *listVC = [[ChatListViewControlleralloc]initWithDisplayConversationTypes:@[[NSNumbernumberWithInt:ConversationType_GROUP]]collectionConversationType:nil];
listVC.hidesBottomBarWhenPushed =YES;
[self.navigationControllerpushViewController:listVCanimated:YES];
}
//
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION)
{
NSLog(@” … CUSTOMIZATION …”);
}
//
elseif(model.conversationModelType ==RC_CONVERSATION_MODEL_TYPE_PUBLIC_SERVICE)
{
NSLog(@” … SERVICE …”);
}
}
//
– (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource
{
for (int i=0; i<dataSource.count; i++) {
RCConversationModel *model =[dataSourceobjectAtIndex:i];
if (model.conversationType ==ConversationType_SYSTEM
|| [model.lastestMessageisMemberOfClass:RCContactNotificationMessage.class]) {
model.conversationModelType =RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION;
}
}
return dataSource;
}
– (void)rcConversationListTableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath;
{
RCConversationModel *model =self.conversationListDataSource[indexPath.row];
//可以从数据库删除数据
if ([[RCIMClientsharedRCIMClient]removeConversation:ConversationType_SYSTEMtargetId:model.targetId])
{
[self.conversationListDataSourceremoveObjectAtIndex:indexPath.row];
[self.conversationListTableViewreloadData];
}
}
//
– (CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return80.0f;
}
//
– (RCConversationBaseCell *)rcConversationListTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
staticNSString *identifier =@”cellidentifier”;
RCConversationModel *model =self.conversationListDataSource[indexPath.row];
id obj= model.lastestMessage;
if (![objisKindOfClass:RCContactNotificationMessage.class])
{
// to 处理其它类型的系统消息
returnnil;
}
FriendMessageCell *cell = [[FriendMessageCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];
[cellsetFriendMessage:model];
return cell;
}
#pragma mark – 收到消息监听
-(void)didReceiveMessageNotification:(NSNotification *)notification
{
__weaktypeof(&*self) blockSelf_ =self;
//处理好友请求
RCMessage *message = notification.object;
if ([message.contentisMemberOfClass:[RCContactNotificationMessageclass]])
{
RCContactNotificationMessage *msg = (RCContactNotificationMessage *)message.content;//
BOOL isExist =NO;
// 监测请求是否己存在
for (RCConversationModel *modelinself.conversationListDataSource) {
id obj= model.lastestMessage;
if (![objisKindOfClass:RCContactNotificationMessage.class]) {
continue;
}
RCContactNotificationMessage *notiMessage = (RCContactNotificationMessage *)obj;
// 判断sourceId targetUserId 均相同。例:我可以同时向多个userID发送好友请求
if ([msg.sourceUserIdisEqualToString:notiMessage.sourceUserId] && [msg.targetUserIdisEqualToString:notiMessage.targetUserId]) {
isExist =YES;
break;
}
}
if (isExist ==YES)
{
[blockSelf_ refreshConversationTableViewIfNeeded];
}
else
{
// dic 存储用户信息,cell中使用. 用户信息从demo server 获得。
NSDictionary *dic = [NSDictionarydictionary];
RCConversationModel *customModel = [[RCConversationModelalloc]init];
customModel.conversationModelType =RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION;
customModel.extend = dic;
customModel.senderUserId = message.senderUserId;
customModel.lastestMessage = msg;
customModel.sentTime = message.sentTime;
customModel.targetId = message.targetId;
//调用父类刷新未读消息数
[blockSelf_ refreshConversationTableViewWithConversationModel:customModel];
}
[blockSelf_ resetConversationListBackgroundViewIfNeeded];
}else{
[superdidReceiveMessageNotification:notification];
}
}
FriendMessageCell.h 文件
#import <RongIMKit/RongIMKit.h>
@interface FriendMessageCell :RCConversationBaseCell
//
– (void)setFriendMessage:(RCConversationModel *)model;
@end
.m 文件
#import “FriendMessageCell.h”
#import “constheader.h”
#define HEXCOLOR(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue &0xFF00) >>8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0]
@interface FriendMessageCell()
@property (nonatomic,strong)UIImageView *iphoto;
@property (nonatomic,strong)UILabel *labelName;
@property (nonatomic,strong)UILabel *labelDetail;
@property (nonatomic,strong)UILabel *labelTime;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,strong)UIButton *buttonYES;
@property (nonatomic,strong)UIButton *buttonNO;
@property (nonatomic,strong)UIButton *buttonAdd;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UILabel *labelResponse;
@property (nonatomic,strong)RCContactNotificationMessage *msg;
@end
@implementation FriendMessageCell
//
– (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];
if (self) {
[selfsetSelectionStyle:UITableViewCellSelectionStyleNone];
UIImage *image = [UIImageimageNamed:@”icon_me”];
_iphoto = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,40,40)];
_iphoto.clipsToBounds =YES;
_iphoto.layer.cornerRadius =6.0f;
_iphoto.image = image;
_iphoto.backgroundColor = [UIColorblackColor];
[selfaddSubview:_iphoto];
_labelDetail = [[UILabelalloc]initWithFrame:CGRectMake(0,0,240,25)];
[_labelDetailsetFont:[UIFontsystemFontOfSize:11.f]];
[_labelDetailsetTextColor:HEXCOLOR(0x8c8c8c)];
[selfaddSubview:_labelDetail];
_labelName = [[UILabelalloc]initWithFrame:CGRectMake(0,0,240,25)];
[_labelNamesetFont:[UIFontboldSystemFontOfSize:11.f]];
[_labelNamesetTextColor:HEXCOLOR(0x252525)];
[selfaddSubview:_labelName];
_labelTime = [[UILabelalloc]initWithFrame:CGRectMake(0,0,80,24)];
[_labelTimesetFont:[UIFontboldSystemFontOfSize:12.f]];
[_labelTimesetTextColor:HEXCOLOR(0x252525)];
_labelTime.backgroundColor = [UIColorclearColor];
_labelTime.textAlignment =NSTextAlignmentRight;
[selfaddSubview:_labelTime];
_buttonYES = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
_buttonYES.frame =CGRectMake(0,0,40, 25);
_buttonYES.backgroundColor = [UIColorwhiteColor];
[_buttonYESsetTitle:@”同意“forState:UIControlStateNormal];
[_buttonYESaddTarget:selfaction:@selector(yes:)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:_buttonYES];
_buttonNO = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
_buttonNO.frame =CGRectMake(0,0,40, 25);
_buttonNO.backgroundColor = [UIColorwhiteColor];
[_buttonNOsetTitle:@”拒绝“forState:UIControlStateNormal];
[_buttonNOaddTarget:selfaction:@selector(no:)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:_buttonNO];
_buttonAdd = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
_buttonAdd.frame =CGRectMake(0,0,40, 25);
_buttonAdd.backgroundColor = [UIColorwhiteColor];
[_buttonAddsetTitle:@”添加“forState:UIControlStateNormal];
[_buttonAddaddTarget:selfaction:@selector(add:)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:_buttonAdd];
_labelResponse = [[UILabelalloc]initWithFrame:CGRectMake(0,0,120,25)];
_labelResponse.backgroundColor = [UIColorclearColor];
_labelResponse.font = [UIFontsystemFontOfSize:14.0f];
[_labelResponsesetTextColor:[UIColorblueColor]];
_labelResponse.textAlignment =NSTextAlignmentCenter;
[selfaddSubview:_labelResponse];
_line = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,1)];
_line.backgroundColor = [UIColorlightGrayColor];
[selfaddSubview:_line];
}
return self;
}
#pragma mark – custom
//
– (void)setFriendMessage:(RCConversationModel *)model
{
//
[selfdefaultStatus];
id obj= model.lastestMessage;
if (![objisKindOfClass:RCContactNotificationMessage.class]) {
return;
}
_msg = (RCContactNotificationMessage *)obj;
NSMutableDictionary *dic =nil;
if (model.extend !=nil)
{
//用户信息
dic = (NSMutableDictionary *)model.extend;
}
else
{
// todo
}
// 好友推荐
if ([_msg.operationisEqualToString:ContactNotificationMessage_ContactOperationRecommend])
{
_buttonAdd.hidden =NO;
_labelName.text = [NSStringstringWithFormat:@”可能认识的人: sourceID_%@”,_msg.sourceUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
//好友请求验证状态
elseif ([_msg.operationisEqualToString:ContactNotificationMessage_ContactOperationRequestSent])
{
_labelResponse.hidden =NO;
_labelResponse.text =@”请求验证“;
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@”,_msg.targetUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
// 好友请求
elseif ([_msg.operationisEqualToString:ContactNotificationMessage_ContactOperationRequest])
{
_buttonYES.hidden =NO;
_buttonNO.hidden =NO;
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@”,_msg.sourceUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
//接受对方的好友请求或者对方接受我的好友请求(通过targetId判断)
elseif([_msg.operationisEqualToString:ContactNotificationMessage_ContactOperationAcceptResponse])
{
// 接受对方的好友请求
if ([_msg.targetUserIdisEqualToString:USERID])
{
_labelResponse.hidden =NO;
_labelResponse.text =@”己添加“;
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@”,_msg.sourceUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
//对方接受我的好友请求
else
{
assert([_msg.sourceUserIdisEqualToString:USERID]);
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@己同意你的好友请求。“,_msg.targetUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
}
//拒绝对方的好友请求或者对方拒绝我的好友请求(通过targetId判断)
elseif([_msg.operationisEqualToString:ContactNotificationMessage_ContactOperationRejectResponse])
{
// 拒绝对方的好友请求
if ([_msg.targetUserIdisEqualToString:USERID])
{
_labelResponse.hidden =NO;
_labelResponse.text =@”己拒绝“;
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@”,_msg.sourceUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
// 对方拒绝我的好友请求
else
{
assert([_msg.sourceUserIdisEqualToString:USERID]);
_labelName.text = [NSStringstringWithFormat:@”sourceID_%@己同意你的好友请求。“,_msg.targetUserId];
_labelDetail.text = [NSStringstringWithFormat:@”附加消息: %@”,_msg.extra];
}
}
else
{
_labelName.text =@”出错啦“;
_labelDetail.text =@”请检查key(operation)所对应的value值“;
NSLog(@” …错误类型 … “);
}
_labelTime.text = [selfConvertMessageTime:model.sentTime/1000];
//
[selfsetNeedsLayout];
}
//
– (void)layoutSubviews
{
_iphoto.center =CGPointMake(10 +_iphoto.frame.size.width/2,self.frame.size.height/2);
_labelName.center =CGPointMake(185,25);
_labelDetail.center =CGPointMake(185,52);
_labelTime.center =CGPointMake(self.frame.size.width – _labelTime.frame.size.width/2 – 20, 20);
_buttonYES.center =CGPointMake(self.frame.size.width – _buttonYES.frame.size.width,50);
_buttonNO.center =CGPointMake(_buttonYES.center.x – _buttonNO.frame.size.width – 10, 50);
_buttonAdd.center =_buttonYES.center;
_labelResponse.center =CGPointMake(self.frame.size.width – _labelResponse.frame.size.width/2 – 10, 50);
_line.center =CGPointMake(self.frame.size.width/2,self.frame.size.height –1);
}
#pragma mark – private
//
– (void)defaultStatus
{
_labelResponse.hidden =YES;
_buttonYES.hidden =YES;
_buttonNO.hidden =YES;
_buttonAdd.hidden =YES;
}
//
– (void)yes:(UIButton *)button
{
// 首先demo server 同意请求,建立好友关系,再向融云服务发送己同意验证。通过server Api发送给指定用户。Api: https://api.cn.ronghub.com/message/system/publish.[format] 其中:参数content中operation对应value值为 @”AcceptResponse”
//如调试:可使用开发平台后台api进行调试。
// todo
}
//
– (void)no:(UIButton *)button
{
// 同上 参数content中operation对应value值为 @”RejectResponse”
}
//
– (void)add:(UIButton *)button
{
// 同上 参数content中operation对应value值为 @”RequestSent”
}
//
– (NSString *)ConvertMessageTime:(longlong)secs
{
NSString *timeText =nil;
NSDate *messageDate = [NSDatedateWithTimeIntervalSince1970:secs];
NSDateFormatter *formatter = [[NSDateFormatteralloc]init];
[formattersetDateFormat:@”yyyy-MM-dd”];
NSString *strMsgDay = [formatterstringFromDate:messageDate];
NSDate *now = [NSDatedate];
NSString *strToday = [formatterstringFromDate:now];
NSDate *yesterday = [[NSDatealloc]initWithTimeIntervalSinceNow🙁24 *60 *60)];
NSString *strYesterday = [formatterstringFromDate:yesterday];
NSString *_yesterday =nil;
if ([strMsgDayisEqualToString:strToday]) {
[formattersetDateFormat:@”HH’:’mm”];
}elseif ([strMsgDayisEqualToString:strYesterday]) {
_yesterday =NSLocalizedStringFromTable(@”Yesterday”,@”RongCloudKit”,nil);
//[formatter setDateFormat:@”HH:mm”];
}
if (nil != _yesterday) {
timeText = _yesterday; //[_yesterday stringByAppendingFormat:@” %@”, timeText];
}else {
timeText = [formatterstringFromDate:messageDate];
}
return timeText;
}