YOUPAIBBIMSessionVC.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. //
  2. // YOUPAIBBIMSessionVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2021/10/25.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIBBIMSessionVC.h"
  9. #import "YOUPAILCGiftModel.h"
  10. #import "YOUPAIUCIMVideoVC.h"
  11. #import "YOUPAILPChatTipView.h"
  12. #import "YOUPAIZYXianNvBangModel.h"
  13. #import "YOUPAIZYXianNvBangVC.h"
  14. #import "UIViewController+TFPresent.h"
  15. #import <SVGAParser.h>
  16. #import <SVGAPlayer.h>
  17. #import "YOUPAIBBCommonGiftView.h"
  18. #import "YOUPAILCUserShowInfo.h"
  19. #import "YOUPAIBBVideoRequestVC.h"
  20. @interface YOUPAIBBIMSessionVC()<SVGAPlayerDelegate>
  21. @property (nonatomic,strong) UIImageView *youpaipcurrentImgV;
  22. @property (nonatomic,strong) UIButton *youpaipxianNvBangBtn;
  23. @property(nonatomic,strong)YOUPAIZYXianNvBangModel *youpaipfairyInfo;
  24. @property (nonatomic,strong)SVGAPlayer *youpaipsvgaPlayer;
  25. @property (nonatomic,strong)SVGAParser *youpaipparser;
  26. @end
  27. @implementation YOUPAIBBIMSessionVC
  28. - (UIStatusBarStyle)preferredStatusBarStyle{
  29. return UIStatusBarStyleLightContent;
  30. }
  31. - (void)viewWillAppear:(BOOL)animated{
  32. [super viewWillAppear:animated];
  33. // [self youpaifaddTip];
  34. }
  35. - (void)viewWillDisappear:(BOOL)animated{
  36. [super viewWillDisappear:animated];
  37. [[NIMSDK sharedSDK].mediaManager stopRecord];
  38. [[NIMSDK sharedSDK].mediaManager stopPlay];
  39. }
  40. - (void)viewDidLoad{
  41. [super viewDidLoad];
  42. [self youpaifrefreshUserInfo];
  43. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
  44. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  45. self.youpaipsvgaPlayer.delegate = self;
  46. self.youpaipsvgaPlayer.userInteractionEnabled = NO;
  47. [[[UIApplication sharedApplication] keyWindow] addSubview:self.youpaipsvgaPlayer];
  48. self.youpaipsvgaPlayer.hidden = YES;
  49. self.youpaipsvgaPlayer.loops = 1;
  50. self.youpaipsvgaPlayer.clearsAfterStop = true;
  51. self.youpaipparser = [[SVGAParser alloc] init];
  52. }
  53. //反色情提示 add by leo 注释
  54. - (void)youpaifaddTip{
  55. [LCHttpHelper requestWithURLString:ChatTip parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  56. NSDictionary* dict = (NSDictionary*)responseObject;
  57. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  58. if (code==0) {//成功
  59. if ([[[dict objectForKey:@"data"] allKeys] containsObject:@"fairy"]) {
  60. if ((![[LCSaveData getSysId] isEqualToString:self.session.sessionId]) && (![self.session.sessionId isEqualToString:@"11"]) ) {
  61. self.youpaipxianNvBangBtn.hidden = NO;
  62. self.youpaipfairyInfo = [YOUPAIZYXianNvBangModel mj_objectWithKeyValues:[[dict objectForKey:@"data"] objectForKey:@"fairy"]];
  63. }
  64. }else{
  65. self.youpaipxianNvBangBtn.hidden = YES;
  66. }
  67. NSString *tip = [[dict objectForKey:@"data"]objectForKey:@"tip"];
  68. YOUPAILPChatTipView* chatTip = [[YOUPAILPChatTipView alloc]initWithFrame:CGRectMake(0, -40, KScreenWidth, 40)];
  69. chatTip.tipLabel.text = tip;
  70. [self.view addSubview:chatTip];
  71. [UIView animateWithDuration:1 animations:^{
  72. chatTip.frame = CGRectMake(0, 0, KScreenWidth, 40);
  73. }completion:^(BOOL finished) {
  74. if (finished) {
  75. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  76. [UIView animateWithDuration:1 animations:^{
  77. chatTip.frame = CGRectMake(0, -40, KScreenWidth, 40);
  78. }completion:^(BOOL finished) {
  79. if (finished) {
  80. [chatTip removeFromSuperview];
  81. }
  82. }];
  83. });
  84. }
  85. }];
  86. }
  87. } failure:^(NSError *error) {
  88. }];
  89. }
  90. #pragma mark - 刷新对方用户信息
  91. - (void)youpaifrefreshUserInfo{
  92. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[self.session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  93. // NIMUser* user = users[0];
  94. }];
  95. }
  96. #pragma mark - Cell事件 图片/视频点击查看 add by leo 注释
  97. - (BOOL)onTapCell:(NIMKitEvent *)event
  98. {
  99. BOOL youpaiphandled = [super onTapCell:event];
  100. NSString *eventName = event.eventName;
  101. if ([eventName isEqualToString:NIMKitEventNameTapContent])
  102. {
  103. NIMMessage *message = event.messageModel.message;
  104. NSDictionary *actions = [self youpaifcellActions];
  105. NSString *value = actions[@(message.messageType)];
  106. if (value) {
  107. SEL selector = NSSelectorFromString(value);
  108. if (selector && [self respondsToSelector:selector]) {
  109. if (message.messageType == NIMMessageTypeImage) {
  110. self.youpaipcurrentImgV = event.contentImage;
  111. }
  112. SuppressPerformSelectorLeakWarning([self performSelector:selector withObject:message]);
  113. youpaiphandled = YES;
  114. }
  115. }
  116. }
  117. else if([eventName isEqualToString:NIMKitEventNameTapLabelLink])
  118. {
  119. NSString *link = event.data;
  120. NSArray* tempArray = [[LCSaveData getTAppUrl] componentsSeparatedByString:@","];
  121. for (NSString* str in tempArray) {
  122. if([link rangeOfString:str].location !=NSNotFound) {
  123. ZCBaseWebVC* base = [[ZCBaseWebVC alloc]init];
  124. base.contentUrl = link;
  125. [self.navigationController pushViewController:base animated:YES];
  126. }
  127. }
  128. //跳转到控制器
  129. youpaiphandled = YES;
  130. }
  131. if (!youpaiphandled) {
  132. NSAssert(0, @"invalid event");
  133. }
  134. return youpaiphandled;
  135. }
  136. //头像点击事件 add by leo 注释
  137. - (BOOL)onTapAvatar:(NIMMessage *)message{
  138. [self.youpaipsessionInputView endEditing:YES];
  139. YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
  140. // if ([message.from isEqualToString:self.session.sessionId]) {
  141. // vc.youpaipuserId = message.session.sessionId;
  142. // }else{
  143. // vc.youpaipuserId = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  144. // }
  145. // [self.navigationController pushViewController:vc animated:YES];
  146. NSString *userId = @"";
  147. if ([message.from isEqualToString:self.session.sessionId]) {
  148. userId = message.session.sessionId;
  149. }else{
  150. userId = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  151. }
  152. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  153. ParamsId:@([userId intValue])
  154. }];
  155. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  156. RouterViewModel:personalPageVM
  157. } completion:nil];
  158. return YES;
  159. }
  160. #pragma mark - Cell Actions 图片 视频点击事件
  161. - (NSDictionary *)youpaifcellActions
  162. {
  163. static NSDictionary *actions = nil;
  164. static dispatch_once_t onceToken;
  165. dispatch_once(&onceToken, ^{
  166. actions = @{@(NIMMessageTypeImage) : @"showImage:",
  167. @(NIMMessageTypeVideo) : @"showVideo:",
  168. @(NIMMessageTypeCustom): @"showCustom:"};
  169. });
  170. return actions;
  171. }
  172. - (void)showImage:(NIMMessage *)message
  173. {
  174. [self.view endEditing:YES];
  175. NSMutableArray* imageArray = [NSMutableArray array];
  176. for (int i =0; i<self.youpaipinteractor.items.count; i++) {
  177. id modelInArray = [[self.youpaipinteractor items] objectAtIndex:i];
  178. if ([modelInArray isKindOfClass:[NIMMessageModel class]])
  179. {
  180. NIMMessageModel *model = (NIMMessageModel *)modelInArray;
  181. if(model.message.messageType == NIMMessageTypeImage){
  182. [imageArray addObject:model.message];
  183. }
  184. }
  185. }
  186. NSArray* sortImageArray = [(NSArray*)imageArray sortedArrayUsingComparator:^NSComparisonResult(NIMMessage * _Nonnull obj1, NIMMessage * _Nonnull obj2) {
  187. return obj1.timestamp > obj2.timestamp;
  188. }];
  189. NSInteger count = imageArray.count;
  190. NSMutableArray *photos = [NSMutableArray arrayWithCapacity:count];
  191. for (NIMMessage *imageMessage in sortImageArray) {
  192. if (imageMessage.messageType == NIMMessageTypeImage) {
  193. NIMImageObject *object = (NIMImageObject *)imageMessage.messageObject;
  194. YBIBImageData *model = [YBIBImageData new];
  195. model.imageURL = [NSURL URLWithString:object.url];
  196. model.projectiveView = self.youpaipcurrentImgV;
  197. [photos addObject:model];
  198. }
  199. }
  200. if (count!=0) {
  201. YBImageBrowser *browser = [YBImageBrowser new];
  202. browser.dataSourceArray = photos;
  203. browser.currentPage = [sortImageArray indexOfObject:message];
  204. [browser show];
  205. }
  206. }
  207. - (void)showVideo:(NIMMessage *)message
  208. {
  209. NIMVideoObject *object = (NIMVideoObject*)message.messageObject;
  210. YOUPAILCIMVideoVC *playerViewController = [[YOUPAILCIMVideoVC alloc] initWithVideoObject:object];
  211. [self pushEffectPresentToVC:playerViewController];
  212. if(![[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
  213. //如果封面图下载了,点进视频的时候再去下一把封面图
  214. __weak typeof(self) wself = self;
  215. [[NIMSDK sharedSDK].resourceManager download:object.coverUrl filepath:object.coverPath progress:nil completion:^(NSError *error) {
  216. if (!error) {
  217. [wself uiUpdateMessage:message];
  218. }
  219. }];
  220. }
  221. }
  222. //add by leo 注释 自定义消息
  223. - (void)showCustom:(NIMMessage *)message
  224. {
  225. //普通的自定义消息点击事件可以在这里做哦~
  226. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  227. if ([object.attachment isKindOfClass:[YOUPAILCOneImageAttachment class]]) {
  228. YOUPAILCOneImageAttachment *attachment = (YOUPAILCOneImageAttachment *)object.attachment;
  229. if (attachment.link_type==1) {//打开H5页面
  230. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  231. web.contentUrl = attachment.link_url;
  232. [self.navigationController pushViewController:web animated:YES];
  233. }else if (attachment.link_type==2){//跳转本地页面
  234. [self youpaifpageToStr:attachment.link_url];
  235. }
  236. }else if ([object.attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]]){
  237. YOUPAILCMultiImageAttachment *attachment = (YOUPAILCMultiImageAttachment *)object.attachment;
  238. NSDictionary* dic;
  239. if ([message.localExt objectForKey:@"serial"]) {
  240. NSInteger ser = [[message.localExt objectForKey:@"serial"]integerValue];
  241. dic = attachment.imageArray[ser];
  242. }else{
  243. dic = attachment.imageArray[0];
  244. }
  245. if ([[dic objectForKey:@"link_type"] integerValue]==1) {//打开H5页面
  246. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  247. web.contentUrl = [dic objectForKey:@"link_url"];
  248. [self.navigationController pushViewController:web animated:YES];
  249. }else if ([[dic objectForKey:@"link_type"] integerValue]==2){//跳转本地页面
  250. [self youpaifpageToStr:[dic objectForKey:@"link_url"]];
  251. }
  252. }else if([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]]){
  253. YOUPAILCMessageTxtAttachment *attachment = (YOUPAILCMessageTxtAttachment *)object.attachment;
  254. if (attachment.link_type!=0) {
  255. if (attachment.link_type==1) {//打开H5页面
  256. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  257. web.contentUrl = attachment.link_url;
  258. [self.navigationController pushViewController:web animated:YES];
  259. }else if (attachment.link_type==2){//跳转本地页面
  260. [self youpaifpageToStr:attachment.link_url];
  261. }else if(attachment.link_type==3){//执行本地逻辑
  262. NSDictionary* dict = [attachment.link_url mj_JSONObject];
  263. if([[dict objectForKey:@"action"]isEqualToString:@"add_qq_group"]){
  264. NSString* qqgroup = [[dict objectForKey:@"data"]objectForKey:@"groupId"];
  265. NSString* qqkey = [[dict objectForKey:@"data"]objectForKey:@"iosKey"];
  266. NSString *urlStr = [NSString stringWithFormat:@"mqqapi://card/show_pslcard?src_type=internal&version=1&uin=%@&key=%@&card_type=group&source=external", qqgroup,qqkey];
  267. NSURL *url = [NSURL URLWithString:urlStr];
  268. if([[UIApplication sharedApplication] canOpenURL:url]){
  269. [[UIApplication sharedApplication] openURL:url];
  270. }else{
  271. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"你可以加入我们官方QQ群:%@",qqgroup]showtime:3.0];
  272. }
  273. }
  274. }
  275. }
  276. }else if ([object.attachment isKindOfClass:[YOUPAILPFollowAttachment class]]){
  277. YOUPAILPFollowAttachment *attachment = (YOUPAILPFollowAttachment *)object.attachment;
  278. //v1.0.7 type为18跳到聊天页面
  279. if(attachment.type==16||attachment.type==17)
  280. {
  281. // LCUserShowVC* userShow = [[LCUserShowVC alloc]init];
  282. // YOUPAILZUserShowVC* userShow = [[YOUPAILZUserShowVC alloc]init];
  283. // userShow.youpaipuserId = [NSString stringWithFormat:@"%zd",attachment.userid];
  284. // [self.navigationController pushViewController:userShow animated:YES];
  285. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  286. ParamsId:@(attachment.userid)
  287. }];
  288. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  289. RouterViewModel:personalPageVM
  290. } completion:nil];
  291. }
  292. else
  293. {
  294. NSString* userId = [NSString stringWithFormat:@"%zd",attachment.userid];
  295. if (userId) {
  296. NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
  297. if (session) {
  298. @weakify(self);
  299. [ZCHUDHelper show];
  300. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  301. @strongify(self);
  302. [ZCHUDHelper dismiss];
  303. YOUPAIBBIMSessionVC *vc = [[YOUPAIBBIMSessionVC alloc] initWithSession:session];
  304. [self.navigationController pushViewController:vc animated:YES];
  305. }];
  306. }
  307. }
  308. }
  309. }
  310. }
  311. #pragma mark - NIMInputActionDelegate 礼物 视频 语音 照片 啥的 注释by leo
  312. - (void)onCameraClick{
  313. [self.youpaipinteractor mediaShootPressed];
  314. }
  315. - (void)onPhotoClick{
  316. [self.youpaipinteractor mediaPicturePressed];
  317. }
  318. #pragma mark SVGAPlayerDelegate
  319. //- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage
  320. //{
  321. // NSLog(@"percentage == %lf",percentage);
  322. // if (percentage == 1) {
  323. //// [self.player stopAnimation];
  324. //// self.player.hidden = YES;
  325. // }
  326. //}
  327. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player
  328. {
  329. self.youpaipsvgaPlayer.hidden = YES;
  330. }
  331. - (void)onGiftClick{
  332. [self.youpaipsessionInputView endEditing:YES];
  333. YOUPAIBBCommonGiftView *view = [YOUPAIBBCommonGiftView new];
  334. view.isTouchDismiss = YES;
  335. view.youpaipisAnchor = NO;
  336. view.vc = self;
  337. @weakify(self);
  338. [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull giftModel, NSInteger count,NSString*categoryID) {
  339. @strongify(self);
  340. [LCHttpHelper requestWithURLString:SendGift_New parameters:@{@"type":@(2),@"to_uid":self.session.sessionId,@"gift_id":giftModel.youpaipid,@"num":@(count),@"gift_type_id":categoryID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  341. NSDictionary* dict = (NSDictionary*)responseObject;
  342. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  343. if (code==0) {//成功
  344. NSInteger coin = [[[dict objectForKey:@"data"]objectForKey:@"coin"]integerValue];
  345. // [ZCHUDHelper showTitle:@"礼物赠送成功"];
  346. [self.youpaipsvgaPlayer stopAnimation];
  347. if (giftModel.youpaiptype == 1 && ![giftModel.youpaipsvga isEqualToString:@""]) {
  348. self.youpaipsvgaPlayer.hidden = NO;
  349. }
  350. NSString* svgaName = [[giftModel.youpaipsvga componentsSeparatedByString:@"/"] lastObject];
  351. NSLog(@"%@",giftModel.youpaipsvga);
  352. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  353. NSLog(@"%@",svgaCanchesPath);
  354. if (![LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga]){
  355. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,giftModel.youpaipsvga];
  356. @weakify(self);
  357. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  358. @strongify(self);
  359. if (videoItem != nil) {
  360. self.youpaipsvgaPlayer.videoItem = videoItem;
  361. [self.youpaipsvgaPlayer startAnimation];
  362. }
  363. } failureBlock:^(NSError * _Nullable error) {
  364. @strongify(self);
  365. self.youpaipsvgaPlayer.hidden = YES;
  366. }];
  367. [LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga];
  368. }else{
  369. @weakify(self);
  370. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  371. @strongify(self);
  372. if (videoItem != nil) {
  373. self.youpaipsvgaPlayer.videoItem = videoItem;
  374. [self.youpaipsvgaPlayer startAnimation];
  375. }
  376. } failureBlock:^(NSError * _Nonnull error) {
  377. @strongify(self);
  378. self.youpaipsvgaPlayer.hidden = YES;
  379. }];
  380. }
  381. }
  382. } failure:^(NSError *error) {
  383. }];
  384. }];
  385. [self TFPresentVC:view completion:^{
  386. }];
  387. }
  388. - (void)onVideoClick{
  389. if ([self.session.sessionId isEqualToString:[LCSaveData getServerId]]) {
  390. [ZCHUDHelper showTitle:@"暂时不能和客服视频通话"];
  391. return ;
  392. }
  393. //v1.1.2 增加相机权限判断
  394. [UCAuthorityManager cameraAuthority:^{
  395. [self.youpaipsessionInputView endEditing:YES];
  396. [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":self.session.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  397. NSDictionary* dict = (NSDictionary*)responseObject;
  398. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  399. if (code==0) {//成功
  400. NSDictionary *data = [dict objectForKey:@"data"];
  401. YOUPAILCUserShowInfo *info = [YOUPAILCUserShowInfo mj_objectWithKeyValues:[data objectForKey:@"info"]];
  402. YOUPAIBBVideoRequestVC* chatRequest = [[YOUPAIBBVideoRequestVC alloc]init];
  403. YOUPAILCVideoChatModel *videoModel = [[YOUPAILCVideoChatModel alloc] init];
  404. videoModel.youpaiproom_id = [NSString stringWithFormat:@"C%@",[LCTools randomNumberWithLength:6]];
  405. videoModel.youpaipauditState = 1;
  406. videoModel.youpaipfrom_uid = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  407. videoModel.youpaipfrom_nickname = [LCSaveModel getUserModel].youpaipuserinfo.youpaipnickname;
  408. videoModel.youpaipfrom_avatar = [LCSaveModel getUserModel].youpaipuserinfo.youpaipavatar;
  409. videoModel.youpaipto_uid = self.session.sessionId;
  410. videoModel.youpaipto_nickname = info.youpaipnickname;
  411. videoModel.youpaipto_avatar = info.youpaipavatar;
  412. chatRequest.youpaipvideoModel = videoModel;
  413. ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
  414. //modify by leo fix bug ios13
  415. nav.modalPresentationStyle =0;
  416. [self.navigationController presentViewController:nav animated:YES completion:^{
  417. }];
  418. }
  419. } failure:^(NSError *error) {
  420. }];
  421. } denied:^{
  422. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert];
  423. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  424. if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
  425. {
  426. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  427. }
  428. else
  429. {
  430. // 去系统设置页面
  431. if (@available(iOS 10.0, *)) {
  432. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  433. } else {
  434. // Fallback on earlier versions
  435. }
  436. }
  437. }];
  438. UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  439. [systemAlert addAction:cancelAction];
  440. [systemAlert addAction:action];
  441. dispatch_async(dispatch_get_main_queue(), ^{
  442. [self presentViewController: systemAlert animated: YES completion: nil];
  443. });
  444. }];
  445. }
  446. - (void)pushEffectPresentToVC:(UIViewController*)vc{
  447. CATransition *transition = [CATransition animation];
  448. transition.duration = 0.25;
  449. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
  450. transition.type = kCATransitionPush;
  451. transition.subtype = kCATransitionFromTop;
  452. [self.navigationController.view.layer addAnimation:transition forKey:nil];
  453. [self.navigationController pushViewController:vc animated:NO ];
  454. }
  455. //接收消息
  456. - (void)onRecvMessages:(NSArray *)messages
  457. {
  458. [super onRecvMessages:messages];
  459. NIMMessage *message = messages.firstObject;
  460. NIMSession *session = message.session;
  461. if (![session isEqual:self.session] || !messages.count)
  462. {
  463. return;
  464. }
  465. if (message.messageType == NIMMessageTypeCustom){
  466. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  467. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]])
  468. {
  469. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  470. // [ZCHUDHelper showTitle:@"收到一个礼物"];
  471. NSLog(@"%@",attachment.gift_url);
  472. NSLog(@"%@",attachment.gift_svga);
  473. [self.youpaipsvgaPlayer stopAnimation];
  474. if (attachment.gift_type == 1 && ![attachment.gift_svga isEqualToString:@""]) {
  475. self.youpaipsvgaPlayer.hidden = NO;
  476. }
  477. NSString* svgaName = [[attachment.gift_svga componentsSeparatedByString:@"/"] lastObject];
  478. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  479. NSLog(@"%@",svgaCanchesPath);
  480. if (![LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga]){
  481. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,attachment.gift_svga];
  482. @weakify(self);
  483. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  484. @strongify(self);
  485. if (videoItem != nil) {
  486. self.youpaipsvgaPlayer.videoItem = videoItem;
  487. [self.youpaipsvgaPlayer startAnimation];
  488. }
  489. } failureBlock:^(NSError * _Nullable error) {
  490. @strongify(self);
  491. self.youpaipsvgaPlayer.hidden = YES;
  492. }];
  493. [LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga];
  494. }else{
  495. @weakify(self);
  496. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  497. @strongify(self);
  498. if (videoItem != nil) {
  499. self.youpaipsvgaPlayer.videoItem = videoItem;
  500. [self.youpaipsvgaPlayer startAnimation];
  501. }
  502. } failureBlock:^(NSError * _Nonnull error) {
  503. @strongify(self);
  504. self.youpaipsvgaPlayer.hidden = YES;
  505. }];
  506. }
  507. }
  508. }
  509. }
  510. @end