注:從我的CSDN博客轉(zhuǎn)入
這個(gè)需求真心把我郁悶了半天,很少見要從聊天信息的文本跳轉(zhuǎn)到原生的請(qǐng)求界面去
方案1:---有BUG -不建議采取此方式
1.找到EMChatTextBubbleView.m
2.此處是環(huán)信的文本點(diǎn)擊事件,再次獲取擴(kuò)展字段,進(jìn)行判斷是否匹配,匹配成功發(fā)送通知
-(void)bubbleViewPressed:(id)sender
{
UITapGestureRecognizer *tap = (UITapGestureRecognizer *)sender;
CGPoint point = [tap locationInView:self];
CFIndex charIndex = [self characterIndexAtPoint:point];
[self highlightLinksWithIndex:NSNotFound];
NSDictionary *extTest = self.model.message.ext;
NSLog(@"文本消息%@",extTest);
NSString * extString= [NSString stringWithFormat:@"%@",[extTest objectForKey:@"type"]];
if([extString isEqualToString:@"1"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"jumpUserRquestNotification"
object:nil];
}
for (NSTextCheckingResult *match in _urlMatches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSRange matchRange = [match range];
if ([self isIndex:charIndex inRange:matchRange]) {
[self routerEventWithName:kRouterEventTextURLTapEventName userInfo:@{KMESSAGEKEY:self.model, @"url":match.URL}];
break;
}
} else if ([match resultType] == NSTextCheckingTypeReplacement) {
NSRange matchRange = [match range];
if ([self isIndex:charIndex inRange:matchRange]) {
[self routerEventWithName:kRouterEventMenuTapEventName userInfo:@{KMESSAGEKEY:self.model, @"text":match.replacementString}];
break;
}
}
}
}
3.前往ChatViewController.m ViewDidLoad里定義通知,監(jiān)聽方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pressbtn:) name:@"jumpUserRquestNotification" object:nil];
方案2:
1.消息界面箭頭所指的地方點(diǎn)擊跳轉(zhuǎn)
2.找到ChatViewController.m
方法定位:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < [self.dataSource count]) {
id obj = [self.dataSource objectAtIndex:indexPath.row];
if ([obj isKindOfClass:[NSString class]]) {
EMChatTimeCell *timeCell = (EMChatTimeCell *)[tableView dequeueReusableCellWithIdentifier:@"MessageCellTime"];
if (timeCell == nil) {
timeCell = [[EMChatTimeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MessageCellTime"];
timeCell.backgroundColor = [UIColor clearColor];
timeCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
timeCell.textLabel.text = (NSString *)obj;
return timeCell;
}
else{
MessageModel *model = (MessageModel *)obj;
PopAccount *accuount = [PopAccountTool account];
NSString *cellIdentifier = [EMChatViewCell cellIdentifierForMessageModel:model];
EMChatViewCell *cell = (EMChatViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//此處給cell添加點(diǎn)擊方法addTarget:self action:@selector(pressbtn:)
if (cell == nil) {
cell = [[EMChatViewCell alloc] initWithMessageModel:model reuseIdentifier:cellIdentifier addTarget:self action:@selector(pressbtn:)];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (model.isSender) {
model.headImageURL = [NSURL URLWithString:accuount.facefile];
}else{
model.headImageURL = [NSURL URLWithString:self.receiverHeaderUrl];
}
cell.messageModel = model;
cell.tag = indexPath.row+1;
return cell;
}
}
return nil;
}
3.獲取環(huán)信提供的擴(kuò)展字段和我方服務(wù)器發(fā)出消息的擴(kuò)展字段進(jìn)行匹配
-(void)pressbtn:(id)sender{
MessageModel *model = [self.dataSource objectAtIndex:1];
NSDictionary *dicExt = model.message.ext;
NSString *extString = [NSString stringWithFormat:@"%@",[dicExt objectForKey:@"type"]];
if ([extString isEqualToString:@"1"]) {
RceiveViewController * rect = [[RceiveViewController alloc]init];
UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:rect];
[self presentViewController:nav animated:YES completion:nil];
}