Files
xj-ios/XinjiangProject/XinjiangProject/Project/TUIChat/ChatViewController.m
T
jiayangyangandClaude Opus 4.7 8a8a914a8c feat(sos): 应急就医群视频通话加号邀请及健康档案详情页接口对接
- 多人视频页面恢复右上角加号按钮,接入自有半屏群成员面板
- 选人后自动发起视频通话邀请并即时显示受邀成员
- IM 登录同步 setSelfInfo,解决通话成员显示 ID 问题
- 健康档案详情页接入一人一案接口,移除硬编码数据
- 新增 Pods 修改记录文档

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-20 17:56:10 +08:00

1383 lines
53 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ChatViewController.m
// XinjiangProject
//
// Created by 仁康信息 on 2023/2/13.
//
#import "ChatViewController.h"
#import "TUIC2CChatViewController.h"
#import "TUIMessageDataProvider.h"
#import "TUIChatDataProvider.h"
#import "ChatMapViewController.h"
#import <CommonCrypto/CommonDigest.h>
#import "evaluationPopView.h"
#import "EndSystemSoSCell.h"
#import "DoctorIDCardMessageCell.h"
#import "healthDataCustomCell.h"
#import "XJExpertMainViewController.h"
#import "SendHealthDataViewController.h"
#import "CurrentLocationViewController.h"
#import "CustomMapMessageCell.h"
#import "TUIGroupMemberCellData.h"
#import "XJSelectContactViewController.h"
#import "TUITextMessageCellData.h"
#import "QuestionViewController.h"
#import "SendReportModel.h"
#import "QuesstionDetailLookFileViewController.h"
#import "TUIGroupChatViewController.h"
#import "UIImage+RoundedCorner.h"
#import <CoreLocation/CoreLocation.h>
#import "LookFileDataModel.h"
#import "PopupView.h"
#import "CustomTUIBaseMessageController.h"
#import "DoctorHomePageDetailVC.h"
#import "ArticleCardMessageCell.h"
#import "XJFirstAidResourceDetailVC.h"
#import "XJWeChatManager.h"
#import <SDWebImage/SDImageCache.h>
//自定义map
#define BussinessID_CustomMap @"TIMLocationElem"
//自定义评论
#define BussinessID_CustomReview @"CustomReview"
//自定义档案
#define BussinessID_CustomHealthData @"archives"
//自定义医生名片
#define BussinessID_CustomDoctorCard @"business_card"
@class TUIChatDataProvider;
@interface ChatViewController ()<V2TIMSimpleMsgListener,TUIChatBaseDataProviderDelegate,IMCustomDeleagte,TUIMessageCellDelegate,TUIBaseMessageControllerDelegate,TUICallObserver,V2TIMConversationListener,CLLocationManagerDelegate,UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) TUIC2CChatViewController *vc;
@property (nonatomic, strong) TUIGroupChatViewController * groupvc;
@property (nonatomic, strong) evaluationPopView * popView;
@property (nonatomic, assign) CGFloat starNumber;
@property (nonatomic, strong) NSString * evlationConnte;
@property (nonatomic, strong) PopupView *popupView;
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) NSString * userID;
//定位相关
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, copy) NSString * doctorCardID;
// 右侧群成员面板
@property (nonatomic, strong) UIView *memberPanel;
@property (nonatomic, strong) UIView *memberOverlay;
@property (nonatomic, strong) UITableView *memberTableView;
@property (nonatomic, strong) UILabel *memberTitleLabel;
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *memberList;
@end
@implementation ChatViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = self.navTitle;
// self 为 id<V2TIMSignalingListener>
self.view.backgroundColor = CViewBgColor;
//聊天记录
// [self addNavigationItemWithImageNames:@[@"sangedian"] isLeft:false target:self action:@selector(foundMoreHistory) tags:@[@"1000"]];
// 启用侧滑返回手势
// self.navigationController.interactivePopGestureRecognizer.delegate = self;
// self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//
// // 创建自定义手势识别器
// UIScreenEdgePanGestureRecognizer *panGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
// panGesture.edges = UIRectEdgeLeft;
// [self.view addGestureRecognizer:panGesture];
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
[[TUICallEngine createInstance] addObserver:self];
[[V2TIMManager sharedInstance] addConversationListener:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowAction:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideAction:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendReportMessage:) name:@"sendReport" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendHealthMessage:) name:@"sendHealth" object:nil];
[self addNavigationItemWithImageNames:@[@"whiteBack_icon"] isLeft:YES target:self action:@selector(backUp) tags:@[@200]];
// 右上角三个点(仅急救员入口显示)
if (self.isFromFirstAid) {
UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[moreBtn setTitle:@"···" forState:UIControlStateNormal];
moreBtn.titleLabel.font = [UIFont boldSystemFontOfSize:22];
[moreBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
[moreBtn addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:moreBtn];
}
TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init];
HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo];
// TUIC2CChatViewController
TUIC2CChatViewController *vc = [[TUIC2CChatViewController alloc] init];
//发送
self.vc = vc;
vc.messageController.delegate = self;
[vc setConversationData:data];
// 显示翻译按钮
// TUIChatConfig.defaultConfig.enableTextTranslation = YES;
//不显示视频和语音
[TUIChatConfig defaultConfig].enableVideoCall = self.isVideo; // YES:开启,NO:关闭
[TUIChatConfig defaultConfig].enableAudioCall = NO; // YES:开启,NO:关闭
[TUIChatConfig defaultConfig].backgroudColor = CViewBgColor;
//是否显示发送报告
[TUIChatConfig defaultConfig].enableSendReportCall = true;
[TUIChatConfig defaultConfig].enableSendHealthDataCall = self.eablehaveHelathData;
[TUIChatConfig defaultConfig].enableMapCall = self.eableMapTools;
[TUIChatConfig defaultConfig].isEvealCell = self.isEveal; // YES:开启,NO:关闭
TUIConfig *config = [TUIConfig defaultConfig];
config.avatarType = TAvatarTypeRounded;
// 修改默认头像
if ([user.sex integerValue] == 1) { //女[]
config.defaultAvatarImage = [UIImage imageNamed:@"heard_woman"];
}else
{
config.defaultAvatarImage = [UIImage imageNamed:@"heard_man"];
}
// 修改默认群组头像
// 禁用群组九宫格头像
config.enableGroupGridAvatar = NO;
// 设置发送文字消息的字体和颜色
// [TUITextMessageCellData setOutgoingTextFont:[UIFont systemFontOfSize:15]];
// [TUITextMessageCellData setOutgoingTextColor:[UIColor blackColor]];
// // 设置接收文字消息的字体和颜色
// [TUITextMessageCellData setIncommingTextFont:[UIFont systemFontOfSize:15]];
// [TUITextMessageCellData setIncommingTextColor:[UIColor blueColor]];
UIImage *defaultImage = [[TUIImageCache sharedInstance] getResourceFromCache:TUIChatImagePath(@"SenderTextNodeBkgHL")];
UIImage * gOutgoingHighlightedBubble =
[TUIChatDynamicImage(@"chat_bubble_send_img", defaultImage) resizableImageWithCapInsets:UIEdgeInsetsFromString(@"{12,12,12,12}")
resizingMode:UIImageResizingModeStretch];
UIImage *whiteImage = [[TUIImageCache sharedInstance] getResourceFromCache:TUIChatImagePath(@"SenderTextNodeBkgHL")];
UIImage * whiteimg = [[UIImage imageWithColor:KWhiteColor] resizableImageWithCapInsets:UIEdgeInsetsFromString(@"{12,12,12,12}") resizingMode:UIImageResizingModeStretch];
UIImage *roundedImage = [whiteimg roundCornersWithRadius:20.0f];
// 设置发送气泡,包括普通状态和选中状态
[TUIBubbleMessageCellData setOutgoingBubble:roundedImage];
[TUIBubbleMessageCellData setOutgoingHighlightedBubble:roundedImage];
// 设置接收气泡,包括普通状态和选中状态
[TUIBubbleMessageCellData setIncommingBubble:gOutgoingHighlightedBubble];
[TUIBubbleMessageCellData setIncommingHighlightedBubble:gOutgoingHighlightedBubble];
// 把 TUIC2CChatViewController 添加到自己的 ViewController
if( self.isGroupID == false) {
data.userID = self.chatID;
TUIC2CChatViewController *vc = [[TUIC2CChatViewController alloc] init];
self.vc = vc;
[vc setConversationData:data];
[self addChildViewController:vc];
self.view.backgroundColor = UIColorHex(#EEEEEE);
[self.view addSubview:vc.view];
// addSubview 触发 vc.viewDidLoad 后 messageController 才被创建,必须在这之后设 delegate
vc.messageController.delegate = self;
vc.needScrollToBottom = true;
vc.customDelegate = self;
}
else
{
data.groupID = self.chatID;
TUIGroupChatViewController * vc = [[TUIGroupChatViewController alloc] init];
self.groupvc = vc;
[vc setConversationData:data];
[self addChildViewController:vc];
self.view.backgroundColor = UIColorHex(#EEEEEE);
[self.view addSubview:vc.view];
// addSubview 触发 vc.viewDidLoad 后 messageController 才被创建,必须在这之后设 delegate
vc.messageController.delegate = self;
vc.needScrollToBottom = true;
vc.customDelegate = self;
}
// self.view.backgroundColor = UIColorHex(#EEEEEE);
if ([self.tfNew integerValue] == 1) {
[ESCTUIManager sendGroupVideo:self.chatID withUserIdList:self.member];
TUICallingViewManager *manager = [[TUICallKit createInstance] valueForKey:@"callingViewManager"];
manager.addUserDelegate = self;
}
//主动发送一条消息
//如果点击跳过进入 不操作 非跳过 发送健康档案 2=非跳过
if (self.JumpType == 2 && self.questionType == 2) {
[self sendQuestionInfoMessage];
}
if (self.endRecordType == 100) {
if( self.isGroupID == false) {
self.vc.inputController.view.hidden = YES;
}else
{
self.groupvc.inputController.view.hidden = YES;
}
}
// [self ChatsendReview];
}
- (void)foundMoreHistory {
[EasyTextView showInfoText:@"功能待完善"];
// if (!self.popupView) {
// CGFloat popupWidth = 80.0;
// CGFloat popupHeight = 40.0;
// CGRect popupFrame = CGRectMake((self.view.bounds.size.width - popupWidth) - kRealValue(15), 10, popupWidth, popupHeight);
//
// // 创建透明背景视图
// self.backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
// self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
// [self.view addSubview:self.backgroundView];
//
// // 添加点击手势以隐藏弹窗
// UITapGestureRecognizer *backgroundTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopup)];
// [self.backgroundView addGestureRecognizer:backgroundTapGesture];
//
// self.popupView = [[PopupView alloc] initWithFrame:popupFrame];
// __weak typeof(self) weakSelf = self;
// self.popupView.tapHandler = ^{
// [weakSelf handlePopupTap];
// };
//
// [self.view addSubview:self.popupView];
// } else {
// self.popupView.hidden = NO;
// self.backgroundView.hidden = NO;
// }
}
#pragma mark:医生详情 //头像点击
- (void)chatSelectedHeardImg:(TUIMessageCell *)cell {
if (!cell.messageData.innerMessage.isSelf)
{
// NSString * userID = cell.messageData.innerMessage.sender;
// self.userID = userID;
// [self getIsSmallHelp:userID];
}
}
- (void)getIsSmallHelp:(NSString *)userid {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:userid forKey:@"helpId"];
XJPNetAPI * smallApi = [[XJPNetAPI alloc] init:self tag:@"smallAPI" NeedToken:@""];
[smallApi GetisSmallHelp:parmDic];
}
- (void)hidePopup {
self.popupView.hidden = YES;
self.backgroundView.hidden = YES;
}
- (void)handlePopupTap {
NSLog(@"PopupView tapped");
[self hidePopup];
CustomTUIBaseMessageController * customVC = [[CustomTUIBaseMessageController alloc] init];
customVC.groupID = self.chatID;
[self.navigationController pushViewController:customVC animated:YES];
}
-(void)backUp {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - TUICallingViewManagerDelegate
- (BOOL)callingViewManagerDidTapAddUser:(TUICallingViewManager *)manager {
[self moreAction];
return YES;
}
#pragma mark: 右上角更多(群成员侧滑面板)
- (void)moreAction {
if (!self.isGroupID) return;
if (self.memberPanel) { [self hideMemberPanel]; return; }
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
CGFloat panelW = kScreenWidth - 94;
// 半透明遮罩
self.memberOverlay = [[UIView alloc] initWithFrame:keyWindow.bounds];
self.memberOverlay.backgroundColor = RGBA(0, 0, 0, 0.4);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideMemberPanel)];
[self.memberOverlay addGestureRecognizer:tap];
[keyWindow addSubview:self.memberOverlay];
// 右侧面板
self.memberPanel = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth, 0, panelW, kScreenHeight)];
self.memberPanel.backgroundColor = KWhiteColor;
[keyWindow addSubview:self.memberPanel];
// 头部区域
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, panelW, kStatusBarHeight + 44)];
headerView.backgroundColor = KWhiteColor;
[self.memberPanel addSubview:headerView];
self.memberTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, kStatusBarHeight, panelW - 56, 44)];
self.memberTitleLabel.text = @"群成员";
self.memberTitleLabel.textAlignment = NSTextAlignmentLeft;
self.memberTitleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
self.memberTitleLabel.textColor = UIColorHex(0x070809);
[headerView addSubview:self.memberTitleLabel];
// 关闭按钮
UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(panelW - 44, kStatusBarHeight, 44, 44)];
[closeBtn setTitle:@"✕" forState:UIControlStateNormal];
[closeBtn setTitleColor:UIColorHex(0x070809) forState:UIControlStateNormal];
[closeBtn addTarget:self action:@selector(hideMemberPanel) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:closeBtn];
// 头部分割线
UIView *headerLine = [[UIView alloc] initWithFrame:CGRectMake(12, headerView.bounds.size.height - 1, panelW - 12, 1)];
headerLine.backgroundColor = UIColorHex(0xEAECF1);
[headerView addSubview:headerLine];
// 成员列表
CGFloat tableY = kStatusBarHeight + 44;
self.memberTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, tableY, panelW, kScreenHeight - tableY) style:UITableViewStylePlain];
self.memberTableView.delegate = self;
self.memberTableView.dataSource = self;
self.memberTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.memberTableView.rowHeight = 68;
self.memberTableView.tableFooterView = [self makeAddMemberFooterView:panelW];
[self.memberPanel addSubview:self.memberTableView];
// 动画滑入
[UIView animateWithDuration:0.25 animations:^{
self.memberPanel.frame = CGRectMake(kScreenWidth - panelW, 0, panelW, kScreenHeight);
}];
[self loadGroupMembers];
}
- (UIView *)makeAddMemberFooterView:(CGFloat)panelW {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, panelW, 20 + 49)];
footer.backgroundColor = KWhiteColor;
UIButton *addBtn = [[UIButton alloc] initWithFrame:CGRectMake(11, 20, panelW - 22, 49)];
addBtn.backgroundColor = [UIColorHex(0x2EB8B2) colorWithAlphaComponent:0.12];
addBtn.layer.cornerRadius = 8;
addBtn.layer.borderWidth = 1;
addBtn.layer.borderColor = UIColorHex(0x2EB8B2).CGColor;
[addBtn addTarget:self action:@selector(addMemberAction) forControlEvents:UIControlEventTouchUpInside];
UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, (49 - 18) / 2, 18, 18)];
icon.image = [UIImage imageNamed:@"firstAid_add_icon"];
icon.contentMode = UIViewContentModeScaleAspectFit;
[addBtn addSubview:icon];
UILabel *btnTitle = [[UILabel alloc] init];
btnTitle.text = @"添加成员";
btnTitle.textColor = UIColorHex(0x2EB8B2);
btnTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
[btnTitle sizeToFit];
CGFloat totalW = 18 + 6 + btnTitle.bounds.size.width;
icon.frame = CGRectMake((addBtn.bounds.size.width - totalW) / 2, (49 - 18) / 2, 18, 18);
btnTitle.frame = CGRectMake(icon.frame.origin.x + 18 + 6, (49 - btnTitle.bounds.size.height) / 2, btnTitle.bounds.size.width, btnTitle.bounds.size.height);
[addBtn addSubview:btnTitle];
[footer addSubview:addBtn];
return footer;
}
- (void)hideMemberPanel {
CGFloat panelW = kScreenWidth - 94;
[UIView animateWithDuration:0.25 animations:^{
self.memberPanel.frame = CGRectMake(kScreenWidth, 0, panelW, kScreenHeight);
} completion:^(BOOL finished) {
[self.memberOverlay removeFromSuperview];
[self.memberPanel removeFromSuperview];
self.memberOverlay = nil;
self.memberPanel = nil;
self.memberTableView = nil;
self.memberList = nil;
}];
}
- (void)loadGroupMembers {
self.memberList = [NSMutableArray array];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:self.chatID forKey:@"sessionId"];
XJPNetAPI *api = [[XJPNetAPI alloc] init:self tag:@"GROUPMEMBERLIST" NeedToken:@""];
[api getActualGroupMemberList:params];
}
/// memberType 转中文
- (NSString *)memberTypeNameFromValue:(NSInteger)memberType {
switch (memberType) {
case -1: return @"发起人";
case 0: return @"操作人员";
case 1: return @"专业人员";
case 2: return @"员工";
default: return @"";
}
}
- (void)addMemberAction {
[self hideMemberPanel];
XJSelectContactViewController *selectVC = [[XJSelectContactViewController alloc] init];
selectVC.chatID = self.chatID;
selectVC.groupId = self.chatID;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:selectVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow.rootViewController presentViewController:nav animated:YES completion:nil];
}
#pragma mark - 群成员列表
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView != self.memberTableView || !self.memberList) return 0;
return self.memberList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView != self.memberTableView || indexPath.row >= self.memberList.count) return [UITableViewCell new];
static NSString *cellId = @"MemberCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGFloat panelW = kScreenWidth - 94;
// 头像
UIImageView *avatar = [[UIImageView alloc] initWithFrame:CGRectMake(12, 11, 45, 45)];
avatar.tag = 100;
avatar.layer.cornerRadius = 8;
avatar.layer.masksToBounds = YES;
[cell.contentView addSubview:avatar];
// 姓名
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.tag = 101;
nameLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
nameLabel.textColor = UIColorHex(0x070809);
[cell.contentView addSubview:nameLabel];
// 本人标识
UILabel *selfBadge = [[UILabel alloc] init];
selfBadge.tag = 105;
selfBadge.text = @"本人";
selfBadge.font = [UIFont systemFontOfSize:10 weight:UIFontWeightSemibold];
selfBadge.textColor = UIColorHex(0x2EB8B2);
selfBadge.backgroundColor = [UIColorHex(0x2EB8B2) colorWithAlphaComponent:0.12];
selfBadge.textAlignment = NSTextAlignmentCenter;
selfBadge.layer.cornerRadius = 4;
selfBadge.layer.masksToBounds = YES;
selfBadge.hidden = YES;
[cell.contentView addSubview:selfBadge];
// 成员类型
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 42, panelW - 132, 14)];
titleLabel.tag = 102;
titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
titleLabel.textColor = UIColorHex(0x808080);
[cell.contentView addSubview:titleLabel];
// 电话按钮
UIButton *phoneBtn = [[UIButton alloc] initWithFrame:CGRectMake(panelW - 47, 20, 32, 32)];
phoneBtn.tag = 103;
[phoneBtn setImage:[UIImage imageNamed:@"firstAid_phone_icon"] forState:UIControlStateNormal];
[phoneBtn addTarget:self action:@selector(callMemberAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:phoneBtn];
// 分割线
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(70, 67, panelW - 70, 1)];
line.tag = 104;
line.backgroundColor = UIColorHex(0xEAECF1);
[cell.contentView addSubview:line];
}
NSDictionary *member = self.memberList[indexPath.row];
UIImageView *avatar = [cell.contentView viewWithTag:100];
UILabel *nameLabel = [cell.contentView viewWithTag:101];
UILabel *titleLabel = [cell.contentView viewWithTag:102];
UILabel *selfBadge = [cell.contentView viewWithTag:105];
CGFloat panelW = kScreenWidth - 94;
// 姓名
NSString *userName = member[@"userName"] ?: @"";
nameLabel.text = userName;
CGSize nameSize = [userName sizeWithAttributes:@{NSFontAttributeName: nameLabel.font}];
nameLabel.frame = CGRectMake(70, 15, nameSize.width, 17);
// 本人标识
BOOL isSelfUser = [member[@"isSelf"] integerValue] == 1;
if (isSelfUser) {
selfBadge.hidden = NO;
selfBadge.frame = CGRectMake(CGRectGetMaxX(nameLabel.frame) + 6, 16, 30, 16);
} else {
selfBadge.hidden = YES;
}
// 成员类型
titleLabel.text = [self memberTypeNameFromValue:[member[@"memberType"] integerValue]];
NSString *avatarPath = member[@"avatar"];
if (avatarPath.length > 0) {
NSString *fullUrl = [avatarPath hasPrefix:@"http"] ? avatarPath : [NSString stringWithFormat:@"%@%@", ResourceAddress, avatarPath];
[avatar sd_setImageWithURL:[NSURL URLWithString:fullUrl] placeholderImage:[UIImage imageNamed:@"heard_man"]];
} else {
avatar.image = [UIImage imageNamed:@"heard_man"];
}
return cell;
}
- (void)callMemberAction:(UIButton *)sender {
UITableViewCell *cell = (UITableViewCell *)sender.superview.superview;
NSIndexPath *indexPath = [self.memberTableView indexPathForCell:cell];
if (!indexPath || indexPath.row >= self.memberList.count) return;
NSDictionary *member = self.memberList[indexPath.row];
NSString *phone = member[@"phone"];
if (phone.length == 0) {
[EasyTextView showErrorText:@"暂无手机号"];
return;
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", phone]] options:nil completionHandler:nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark:跳转到地图选择页
- (void)jumpChatMapView {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}
#pragma mark:结束咨询
- (void)sendChatEndQuestionAction {
////1 应急 2 图文咨询 3 音视频咨询 小助手
if (self.questionType == 1) {
[self showMBProgressHUDWithString:@"正在结束本次应急" autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:self.sosEnd_id forKey:@"id"];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"ENDSOSAPI" NeedToken:@""];
[endApi PostEndSoSIMQuestion:parmDic];
}
if (self.questionType == 2) {
[self showMBProgressHUDWithString:@"正在结束本次会话" autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:self.pictureEnd_id forKey:@"id"];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"ENDPICTUREAPI" NeedToken:@""];
[endApi GetEndPictureEndIMQuestion:parmDic];
}
if (!ValidStr(self.smallHelp_id)) {
[self showMBProgressHUDWithString:@"正在结束本次会话" autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:self.smallHelp_id forKey:@"id"];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"ENDPICTUREAPI" NeedToken:@""];
[endApi GetEndPictureEndIMQuestion:parmDic];
}
}
#pragma mark:发送健康档案
//主动发一条消息:健康档案 带联系人数据
- (void)sendQuestionInfoMessage {
//直接请求档案详情
[self getFileDetail];
}
- (void)getFileDetail {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
if (!ValidStr(self.dangan_id) ) {
[parmDic setObject:self.dangan_id forKey:@"id"];
}
XJPNetAPI * upApi = [[XJPNetAPI alloc] init:self tag:@"FILEDATA" NeedToken:@""];
[upApi GetLookModficalMemberShipFileData:parmDic];
}
- (void)questionChatSendHealthData {
SendHealthDataViewController * senVC = [[SendHealthDataViewController alloc] init];
if ([self.kuaisuzixun intValue] == 1) {
senVC.memberId_id = @"";
}else
{
senVC.memberId_id = self.disModel.memberId_id;
}
if (!ValidStr(self.medicalRecordsId)) //我的咨询跳转来的
{
senVC.memberId_id = self.medicalRecordsId;
}
[self.navigationController pushViewController:senVC animated:YES];
}
- (void)lookLocationDetail:(TUIMessageCell *)cel {
// DLog(@"%@",cel.messageData.innerMessage.locationElem.longitude);
CurrentLocationViewController * currVC = [[CurrentLocationViewController alloc] init];
currVC.longitude = cel.messageData.innerMessage.locationElem.longitude;
currVC.latitude = cel.messageData.innerMessage.locationElem.latitude;
[self.navigationController pushViewController:currVC animated:YES];
}
#pragma mark:发送个人名片
- (void)ChatsendDoctorIDCard {
NSDictionary * parmdic = @{BussinessID:BussinessID_CustomDoctorCard};
NSData * messagedata = [NSJSONSerialization dataWithJSONObject:parmdic options:0 error:nil];
V2TIMMessage * message = [[V2TIMManager sharedInstance] createCustomMessage:messagedata];
if( self.isGroupID == false) {
[self.vc sendMessage:message];
}else
{
[self.groupvc sendMessage:message];
}
}
#pragma mark:发送体检报告
- (void)ChatsendReview {
}
- (void)onRecvC2CCustomMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info customData:(NSData *)data
{
id myResult = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
}
- (void)onRecvGroupCustomMessage:(NSString *)msgID groupID:(NSString *)groupID sender:(V2TIMGroupMemberInfo *)info customData:(NSData *)data {
id myResult = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if ([myResult isKindOfClass:[NSDictionary class]]) {
NSDictionary *response = (NSDictionary *)myResult;
SendReportModel * model = [SendReportModel modelWithDictionary:response];
if ([model.businessID isEqualToString:@"system"]) {
if( self.isGroupID == false) {
self.vc.inputController.view.hidden = YES;
}else
{
self.groupvc.inputController.view.hidden = YES;
}
}
}
}
/// 收到 C2C 文本消息
- (void)onRecvC2CTextMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info text:(NSString *)text{
}
#pragma mark:发起评价
- (void)chatevlationDoctorStarView:(TUIMessageCell *)cell{
// DLog(@"-----------%@",@"我是评价");
if ([cell isKindOfClass:EndSystemSoSCell.class]) {
EndSystemSoSCell * endCell = cell;
if (endCell.reviewBtn.hidden == false && [TUIChatConfig defaultConfig].isEvealCell == false ) {
evaluationPopView * popView = [[evaluationPopView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
self.popView = popView;
popView.popBlock = ^(CGFloat starNumber, BOOL isSecrect, NSString * _Nonnull evaluationString) {
NSString * niming = isSecrect == YES? @"1":@"0";
self.starNumber = starNumber;
self.evlationConnte = evaluationString;
[self doctorSourceWithStarNumaber:starNumber withContext:evaluationString isKnow:niming];
};
[[UIApplication sharedApplication].keyWindow addSubview:popView];
}
}
if ([cell isKindOfClass:DoctorIDCardMessageCell.class]) {
DoctorIDCardMessageCell * endCell = cell;
NSLog(@"--%@",endCell.messageData.innerMessage.msgID);
NSLog(@"--%@",endCell.messageData.innerMessage.groupID);
NSLog(@"--%@",endCell.messageData.innerMessage.userID);
NSString * groupId = endCell.messageData.innerMessage.groupID;
NSString * msgId = endCell.messageData.innerMessage.msgID;
NSString * fromAccount = endCell.messageData.identifier;
// !2025年12月10号 新疆卡片不让点击需求-- 李龙
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:groupId forKey:@"groupId"];
[parmDic setObject:fromAccount forKey:@"fromAccount"];
[parmDic setObject:User_ID forKey:@"toAccount"];
[parmDic setObject:msgId forKey:@"msgId"];
[self RecordCardInfo:parmDic];
//小助手id
endCell.messageData.identifier;
NSDate *currentDate = endCell.messageData.innerMessage.timestamp;
// 获取自1970年1月1日以来的时间间隔(以秒为单位)
NSTimeInterval timeInterval = [currentDate timeIntervalSince1970];
// 将时间间隔转换为10位时间戳
NSInteger tenDigitTimestamp = (NSInteger)timeInterval;
// 打印结果
[self getDocotorInfo:tenDigitTimestamp];
self.doctorCardID = endCell.cardId;
}
if ([cell isKindOfClass:healthDataCustomCell.class]) {
healthDataCustomCell * healthCell = cell;
QuesstionDetailLookFileViewController * experVC= [[QuesstionDetailLookFileViewController alloc] init];
experVC.danganID = healthCell.fileId;
[self.navigationController pushViewController:experVC animated:YES];
}
if ([cell isKindOfClass:ArticleCardMessageCell.class]) {
ArticleCardMessageCell * articleCell = (ArticleCardMessageCell *)cell;
if (articleCell.resourceId.length > 0) {
XJFirstAidResourceDetailVC * detailVC = [[XJFirstAidResourceDetailVC alloc] init];
detailVC.resourceId = articleCell.resourceId;
[self.navigationController pushViewController:detailVC animated:YES];
}
}
}
- (void)getDocotorInfo:(long)sendTime{
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(sendTime) forKey:@"sendTime"];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"TIME" NeedToken:@""];
[endApi GetDoctoresExpireTime:parmDic];
}
- (void)RecordCardInfo:(NSDictionary *)parmDic {
[self showMBProgressHUDOnlyWithString:@"加载中,请稍候..."];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"ClickInfo" NeedToken:@""];
[endApi recordDoctorCardInfoClick:parmDic];
}
#pragma mark:网络请求
- (void)Failed:(NSString*)message tag:(NSString*)tag
{
[self showMBProgressHUDOnlyWithString:message];
[self hiddenAllMBProgressHUD];
}
- (void)Sucess:(id)response tag:(NSString*)tag
{
if ([tag isEqualToString:@"ENDSOSAPI"])
{
[self hiddenAllMBProgressHUD];
NSDictionary * parmDic = response;
if( self.isGroupID == false) {
self.vc.inputController.view.hidden = YES;
}else
{
self.groupvc.inputController.view.hidden = YES;
}
}
if ([tag isEqualToString:@"TIME"])
{
// NSString * isExpired =[NSString stringWithFormat:@"%@",response] ;
//
// if ([isExpired integerValue]== 0) {
// XJExpertMainViewController * experVC= [[XJExpertMainViewController alloc] init];
// experVC.doctorId = self.doctorCardID;
// [self.navigationController pushViewController:experVC animated:YES];
// }else
// {
// [EasyTextView showErrorText:@"医生信息已过期"];
// }
}
if ([tag isEqualToString:@"ClickInfo"]) {
XJExpertMainViewController * experVC= [[XJExpertMainViewController alloc] init];
experVC.doctorId = self.doctorCardID;
[self.navigationController pushViewController:experVC animated:YES];
}
if ([tag isEqualToString:@"ENDPICTUREAPI"]) {
[self hiddenAllMBProgressHUD];
if( self.isGroupID == false) {
self.vc.inputController.view.hidden = YES;
}else
{
self.groupvc.inputController.view.hidden = YES;
}
}
if ([tag isEqualToString:@"DoctorSource"]) {
[EasyTextView showSuccessText:response];
[self hiddenAllMBProgressHUD];
[self.popView removeFromSuperview];
[self backUp];
}
if ([tag isEqualToString:@"loginIMAPI"]) {
[self hiddenAllMBProgressHUD];
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
// 1. 从即时通信 IM 控制台获取应用 SDKAppID。
[ESCTUIManager loginInitTUISDKAppidWith:[model.sdkAppId intValue] UserID:model.userId userSig:model.userSig];
}
if ([tag isEqualToString:@"FILEDATA"]) {
NSDictionary * parmDic = response;
LookFileDataModel * model = [LookFileDataModel modelWithDictionary:parmDic];
[self sendFileDetail:model];
}
if ([tag isEqualToString:@"smallAPI"]) {
bool isSmallHelp = [response boolValue];
if (isSmallHelp == true) {
DoctorHomePageDetailVC * vc = [[DoctorHomePageDetailVC alloc] init];
vc.userID = self.userID;
[self.navigationController pushViewController:vc animated:YES];
}
}
if ([tag isEqualToString:@"GROUPMEMBERLIST"]) {
[self.memberList removeAllObjects];
NSArray *list = [response isKindOfClass:[NSDictionary class]] ? response[@"result"] : response;
if ([list isKindOfClass:[NSArray class]]) {
[self.memberList addObjectsFromArray:list];
}
self.memberTitleLabel.text = [NSString stringWithFormat:@"群成员(%lu)", (unsigned long)self.memberList.count];
[self.memberTableView reloadData];
}
}
- (void)sendFileDetail:(LookFileDataModel *)model {
NSString * sexString;
NSString * ageString;
NSString * nameString;
NSString * memberId;
if (self.disModel) { //顶部个人信息
// //性别
sexString = [self.disModel.gender integerValue] == 1 ?@"女":@"男";
//年龄
ageString = [NSString stringWithFormat:@"%@",self.disModel.age];
//姓名
nameString = [NSString stringWithFormat:@"%@",self.disModel.name];
//id
memberId = [NSString stringWithFormat:@"%@",self.disModel.memberId_id];
}
//档案信息
NSString * tf_id;
if (self.JumpType == 1) {
tf_id = @"";
}
else{
tf_id = model.file_id;
}
//症状描述
NSString * siksDesString = model.medicalDescribe;
//图片数组
NSMutableArray * imageArray = [[NSMutableArray alloc] init];
NSString *imageString = model.image;
NSArray *listImageArray;
if (imageString.length == 0) {
// 如果字符串为空,直接返回空数组
listImageArray = @[];
} else {
// 移除末尾的逗号
if ([imageString hasSuffix:@","]) {
imageString = [imageString substringToIndex:imageString.length - 1];
}
// 分割字符串并过滤空字符串
listImageArray = [[imageString componentsSeparatedByString:@","]
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
}
// NSArray * listImageArray = [model.image componentsSeparatedByString:@","];
for (int i = 0 ; i < listImageArray.count; i ++) {
NSString * photo = [NSString stringWithFormat:@"%@%@",ResourceAddress,listImageArray[i]];
NSString * str1 = @"\\";
photo = [photo stringByReplacingOccurrencesOfString:str1 withString:@"/"];
NSString *encodedString3 = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)photo, (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL, kCFStringEncodingUTF8));
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:encodedString3 forKey:@"bigImageUrl"];
[parmDic setObject:encodedString3 forKey:@"thumbnailUrl"];
[imageArray addObject:parmDic];
}
NSDictionary * parmdic = @{BussinessID:BussinessID_CustomHealthData,
@"gender":sexString,
@"age":ageString,
@"name":nameString,
@"symptomDescription":siksDesString,
@"imageList":imageArray,
@"archivesId":tf_id};
NSData * messagedata = [NSJSONSerialization dataWithJSONObject:parmdic options:0 error:nil];
V2TIMMessage * message = [[V2TIMManager sharedInstance] createCustomMessage:messagedata];
if( self.isGroupID == false) {
[self.vc sendMessage:message];
}else
{
[self.groupvc sendMessage:message];
}
}
- (void)doctorSourceWithStarNumaber:(CGFloat)starNumer withContext:(NSString *)connet isKnow:(NSString *)isNiming{
[self showMBProgressHUDWithString:@"评价中,请稍候..." autoHidden:NO];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(starNumer) forKey:@"score"];
[parmDic setObject:connet forKey:@"context"];
[parmDic setObject:self.pictureEnd_id forKey:@"sessionId"];
[parmDic setObject:isNiming forKey:@"tfUnknow"];
XJPNetAPI * endApi = [[XJPNetAPI alloc] init:self tag:@"DoctorSource" NeedToken:@""];
[endApi PostQustionDoctorScore:parmDic];
}
- (void)sendReportMessage:(NSNotification *)note {
}
- (void)sendHealthMessage:(NSNotification *)note {
diseaseModel * model = note.object;
if (model) {
//性别
NSString * sexString = [self.disModel.gender integerValue] == 1 ?@"女":@"男";
//年龄
NSString * ageString = [NSString stringWithFormat:@"%@",model.age];
//姓名
NSString * nameString = [NSString stringWithFormat:@"%@",model.name];
//id
NSString * memberId = [NSString stringWithFormat:@"%@",model.tfper_id];
//症状描述
NSString * siksDesString = @"";
//图片数组
NSMutableArray * imageArray = [[NSMutableArray alloc] init];
NSString *imageString = model.image;
NSArray *listImageArray;
if (imageString.length == 0) {
// 如果字符串为空,直接返回空数组
listImageArray = @[];
} else {
// 移除末尾的逗号
if ([imageString hasSuffix:@","]) {
imageString = [imageString substringToIndex:imageString.length - 1];
}
// 分割字符串并过滤空字符串
listImageArray = [[imageString componentsSeparatedByString:@","]
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
}
for (int i = 0 ; i < listImageArray.count; i ++) {
NSString * photo = [NSString stringWithFormat:@"%@%@",ResourceAddress,listImageArray[i]];
NSString * str1 = @"\\";
photo = [photo stringByReplacingOccurrencesOfString:str1 withString:@"/"];
NSString *encodedString3 = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)photo, (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL, kCFStringEncodingUTF8));
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:encodedString3 forKey:@"bigImageUrl"];
[parmDic setObject:encodedString3 forKey:@"thumbnailUrl"];
[imageArray addObject:parmDic];
}
siksDesString = model.medicalDescribe;
NSDictionary * parmdic = @{BussinessID:BussinessID_CustomHealthData,@"gender":sexString,@"age":ageString,@"name":nameString,@"symptomDescription":siksDesString,@"imageList":imageArray,@"archivesId":memberId};
NSData * messagedata = [NSJSONSerialization dataWithJSONObject:parmdic options:0 error:nil];
V2TIMMessage * message = [[V2TIMManager sharedInstance] createCustomMessage:messagedata];
if( self.isGroupID == false) {
[self.vc sendMessage:message];
}else
{
[self.groupvc sendMessage:message];
}
}
}
#pragma mark - 键盘处理
/**
* 键盘即将隐藏
*/
- (void)keyboardWillHideAction:(NSNotification *)note
{
// 1.键盘弹出需要的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 2.动画
[UIView animateWithDuration:duration animations:^{
self.popView.evaluationView.frame = CGRectMake(0, kScreenHeight - kRealValue(327), kScreenWidth, kRealValue(327));
}];
}
/**
* 键盘即将弹出
*/
- (void)keyboardWillShowAction:(NSNotification *)note
{
// 1.键盘弹出需要的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 2.动画
[UIView animateWithDuration:duration animations:^{
// 取出键盘高度
CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardH = keyboardF.size.height - 40;
// if (_ThreeInch) {
// self.view.transform = CGAffineTransformMakeTranslation(0, - keyboardH);
// } else {
// self.view.transform = CGAffineTransformMakeTranslation(0, - 50);
// }
self.popView.evaluationView.frame = CGRectMake(0, kScreenHeight - kRealValue(327) - keyboardH, kScreenWidth, kRealValue(327));
}];
}
- (void)loginImAccount {
XJPNetAPI * proctocolApi = [[XJPNetAPI alloc] init:self tag:@"loginIMAPI" NeedToken:nil];
[proctocolApi GetIMLoginAccount:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if( self.isGroupID == false) {
self.vc.needScrollToBottom = true;
}
else
{
self.groupvc .needScrollToBottom = true;
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
//在线时票据过期:此时您需要生成新的 userSig,并再次重新调用初始化。
- (void)onKickedOffline {
[HQCommonUtils keyedArchiverWithData:nil key:LoginUserInfo];
[ESCTUIManager outLoginTUISDK];
KPostNotification(KNotificationLoginStateChange, @NO);
}
- (void)updateConversation:(NSArray *)convList {
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
// 用户还未决定是否授权
[self handleLocationServicesRestricted];
break;
case kCLAuthorizationStatusRestricted:
// 位置服务被限制(例如家长控制)
[self handleLocationServicesRestricted];
break;
case kCLAuthorizationStatusDenied:
// 用户拒绝了位置权限
[self showAlertToOpenSettings];
break;
case kCLAuthorizationStatusAuthorizedAlways:
case kCLAuthorizationStatusAuthorizedWhenInUse:
// 用户授权了位置权限
[self handleLocationServicesAuthorized];
break;
default:
}
}
- (void)handleLocationServicesRestricted {
// 处理位置服务受限的情况
NSLog(@"位置服务被限制");
[self showAlertToOpenSettings];
}
- (void)handleLocationServicesDenied {
// 处理位置服务被拒绝的情况
NSLog(@"位置服务被拒绝");
[self showAlertToOpenSettings];
}
- (void)handleLocationServicesDisabled {
// 处理设备的定位服务被禁用的情况
NSLog(@"设备的定位服务被禁用");
[self showAlertToOpenSettings];
}
- (void)showAlertToOpenSettings {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"定位服务已关闭"
message:@"请在设置中启用定位服务"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settingsURL]) {
[[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:nil];
}
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:settingsAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)handleLocationServicesAuthorized {
// 处理授权成功的情况(例如,开始更新位置信息)
ChatMapViewController * mapVC = [[ChatMapViewController alloc] init];
MJWeakSelf
mapVC.mapBlcok = ^(CLLocationCoordinate2D coordinate, NSString *address) {
V2TIMMessage * message = [[V2TIMManager sharedInstance] createLocationMessage:address ?: @"位置" longitude:coordinate.longitude latitude:coordinate.latitude];
if( self.isGroupID == false) {
[weakSelf.vc sendMessage:message];
}else
{
[weakSelf.groupvc sendMessage:message];
}
};
[self.navigationController pushViewController:mapVC animated:YES];
}
//// 手势处理方法
//- (void)handlePanGesture:(UIScreenEdgePanGestureRecognizer *)gesture {
// if (gesture.state == UIGestureRecognizerStateEnded) {
// NSArray *viewControllers = self.navigationController.viewControllers;
// UIViewController *targetViewController = nil;
//
// // 查找导航堆栈中的目标视图控制器
// for (UIViewController *vc in viewControllers) {
// if ([vc isKindOfClass:[QuestionViewController class]]) {
// targetViewController = vc;
// break;
// }
// }
//
// if (targetViewController) {
// // 如果找到目标视图控制器,则弹出到该视图控制器
// [self.navigationController popToViewController:targetViewController animated:YES];
// } else {
// // 如果没有找到目标视图控制器,则返回到上一页
// [self.navigationController popViewControllerAnimated:YES];
// }
// }
//}
//// UIGestureRecognizerDelegate 方法
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
// // 确保只有在不是根视图控制器时才启用手势
// return self.navigationController.viewControllers.count > 1;
//}
#pragma mark - ————— 地图卡片长按转发微信 —————
- (void)messageController:(TUIBaseMessageController *)controller willDisplayCell:(TUIMessageCell *)cell withData:(TUIMessageCellData *)data {
// 运行时判断,避免直接 import Pods 中未被暴露的头文件
Class mapCellClass = NSClassFromString(@"MapMessageCustomCell");
BOOL isMapCell = [cell isKindOfClass:mapCellClass];
NSLog(@"[ChatVC] willDisplayCell: cell=%@, isMapCell=%d, class=%@", cell, isMapCell, NSStringFromClass([cell class]));
if (isMapCell) {
if ([cell respondsToSelector:@selector(setMapDelegate:)]) {
[cell performSelector:@selector(setMapDelegate:) withObject:self];
NSLog(@"[ChatVC] mapDelegate set to self on %@", cell);
}
}
}
- (void)mapCellDidLongPressWithData:(id)data {
NSLog(@"[ChatVC] mapCellDidLongPress called, data=%@", data);
if (![[XJWeChatManager sharedManager] isWeChatInstalled]) {
[EasyTextView showErrorText:@"未安装微信"];
return;
}
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"转发到微信" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self shareMapToWeChatWithData:data];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
UIViewController *topVC = [self topViewController];
[topVC presentViewController:alert animated:YES completion:nil];
}
- (void)shareMapToWeChatWithData:(id)data {
NSString *address = [data valueForKey:@"text"];
if (![address isKindOfClass:[NSString class]] || address.length == 0) {
address = @"我的位置";
}
CGFloat lat = [[data valueForKey:@"latitude"] doubleValue];
CGFloat lng = [[data valueForKey:@"longitude"] doubleValue];
NSString *encodedAddress = [address stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSString *mapUrl = [NSString stringWithFormat:@"https://uri.amap.com/marker?position=%f,%f&name=%@",
lng, lat, encodedAddress ?: @"位置"];
NSString *imageKey = [data valueForKey:@"MapPictureImg"];
UIImage *thumb = [[SDImageCache sharedImageCache] imageFromCacheForKey:imageKey];
[[XJWeChatManager sharedManager] shareWebpageWithTitle:@"我的位置"
desc:address
webpageUrl:mapUrl
thumbImage:thumb
toScene:0
completion:^(BOOL success, NSString * _Nullable errorMsg) {
if (!success && errorMsg.length > 0) {
[EasyTextView showErrorText:errorMsg];
}
}];
}
- (UIViewController *)topViewController {
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
while (rootVC.presentedViewController) {
rootVC = rootVC.presentedViewController;
}
if ([rootVC isKindOfClass:[UINavigationController class]]) {
return [(UINavigationController *)rootVC topViewController];
}
if ([rootVC isKindOfClass:[UITabBarController class]]) {
UIViewController *selected = [(UITabBarController *)rootVC selectedViewController];
if ([selected isKindOfClass:[UINavigationController class]]) {
return [(UINavigationController *)selected topViewController];
}
return selected;
}
return rootVC;
}
/// 将未实现的 TUIBaseMessageControllerDelegate 方法转发给 TUIBaseChatViewControllerself.vc / self.groupvc
- (id)forwardingTargetForSelector:(SEL)aSelector {
// 优先转发给 C2C 的 vc,其次 groupvc
if ([self.vc respondsToSelector:aSelector]) {
return self.vc;
}
if ([self.groupvc respondsToSelector:aSelector]) {
return self.groupvc;
}
return [super forwardingTargetForSelector:aSelector];
}
@end