From c3d3698952eba830df4bb08a124f728b8d4b150c Mon Sep 17 00:00:00 2001 From: Elon Chan Date: Thu, 14 Jun 2018 22:08:03 +0800 Subject: [PATCH] v2.1.4 update AVOSCloud and AVOSCloudIM SDK to 11.0.0 --- CYLChatKit.podspec | 6 +- .../Example/Class/Module/Main/LCCKUtil.h | 1 + ChatKit-OC/Podfile.lock | 32 +++++----- ChatKit/Class/Model/LCCKCommonUtils.h | 17 +++++ ChatKit/Class/Model/LCCKCommonUtils.m | 29 +++++++++ ChatKit/Class/Model/LCCKMessage.m | 18 ++---- .../LCCKContactListViewController.m | 2 +- .../LCCKConversationViewController.m | 63 +++++++------------ .../Model/LCCKConversationViewModel.m | 12 ++-- .../LCCKChatImageMessageCell.m | 29 ++++----- .../Tool/Service/LCCKConversationService.h | 2 +- .../Tool/Service/LCCKConversationService.m | 41 ++++-------- .../Class/Tool/Service/LCCKSessionService.m | 7 ++- 13 files changed, 133 insertions(+), 126 deletions(-) create mode 100644 ChatKit/Class/Model/LCCKCommonUtils.h create mode 100644 ChatKit/Class/Model/LCCKCommonUtils.m diff --git a/CYLChatKit.podspec b/CYLChatKit.podspec index c8f27a0..efa172c 100644 --- a/CYLChatKit.podspec +++ b/CYLChatKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CYLChatKit" - s.version = "2.1.3" + s.version = "2.1.4" s.summary = "An IM App Framework, support sending text, pictures, audio, video, location messaging, managing address book, more interesting features." s.homepage = "https://github.com/ChenYilong/CYLChatKit" s.license = { :type => 'MIT', :file => 'LICENSE' } @@ -13,8 +13,8 @@ Pod::Spec.new do |s| s.resources = 'ChatKit/Class/Resources/*', 'ChatKit/**/*.xib' s.requires_arc = true - s.dependency "AVOSCloud" , "~> 8.2.0" - s.dependency "AVOSCloudIM", "~> 8.2.0" + s.dependency "AVOSCloud" , "~> 11.0.0" + s.dependency "AVOSCloudIM", "~> 11.0.0" s.dependency "MJRefresh" , "~> 3.1.9" s.dependency "Masonry" , "~> 1.0.1" s.dependency "SDWebImage" , "~> 3.8.0" diff --git a/ChatKit-OC/Example/Class/Module/Main/LCCKUtil.h b/ChatKit-OC/Example/Class/Module/Main/LCCKUtil.h index 4367e9f..528cd5d 100644 --- a/ChatKit-OC/Example/Class/Module/Main/LCCKUtil.h +++ b/ChatKit-OC/Example/Class/Module/Main/LCCKUtil.h @@ -13,6 +13,7 @@ #else #import "LCChatKit.h" #endif + @interface LCCKUtil : NSObject + (BOOL)isIPhoneX; diff --git a/ChatKit-OC/Podfile.lock b/ChatKit-OC/Podfile.lock index bc6f6df..b3863c7 100644 --- a/ChatKit-OC/Podfile.lock +++ b/ChatKit-OC/Podfile.lock @@ -1,17 +1,17 @@ PODS: - - AVOSCloud (8.2.3) - - AVOSCloudIM (8.2.3): - - AVOSCloud (= 8.2.3) - - AVOSCloudIM/_ARC (= 8.2.3) - - AVOSCloudIM/_NOARC (= 8.2.3) - - AVOSCloudIM/_ARC (8.2.3): - - AVOSCloud (= 8.2.3) - - AVOSCloudIM/_NOARC (= 8.2.3) - - AVOSCloudIM/_NOARC (8.2.3): - - AVOSCloud (= 8.2.3) - - CYLChatKit (2.1.2): - - AVOSCloud (~> 8.2.0) - - AVOSCloudIM (~> 8.2.0) + - AVOSCloud (11.0.0) + - AVOSCloudIM (11.0.0): + - AVOSCloud (= 11.0.0) + - AVOSCloudIM/_ARC (= 11.0.0) + - AVOSCloudIM/_NOARC (= 11.0.0) + - AVOSCloudIM/_ARC (11.0.0): + - AVOSCloud (= 11.0.0) + - AVOSCloudIM/_NOARC (= 11.0.0) + - AVOSCloudIM/_NOARC (11.0.0): + - AVOSCloud (= 11.0.0) + - CYLChatKit (2.1.3): + - AVOSCloud (~> 11.0.0) + - AVOSCloudIM (~> 11.0.0) - CYLDeallocBlockExecutor (~> 1.2.0) - DACircularProgress (~> 2.3.1) - FDStackView (~> 1.0) @@ -89,9 +89,9 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - AVOSCloud: 242fe402282677149487e70fb993843d03cc7b86 - AVOSCloudIM: 1286d413ec0ed9d237ea9bf0938d13ecf4bb6cc0 - CYLChatKit: c6882d499d28d967e189d4ab1f4dfa996dd350c3 + AVOSCloud: 8ffa848f5f7391fc7594d3671a29cd6f8a14cc2a + AVOSCloudIM: 465af27feb394e50e1b09a7fd2da4645be340cdb + CYLChatKit: a4563933aae675b5438927f2290a7993dbb215ea CYLDeallocBlockExecutor: 1f8e904d846b8dadff88b2e5c2817df974cb63a9 CYLTabBarController: b6e0574c2f5592edfbfc71a1b2be8dc0374cf11a DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71 diff --git a/ChatKit/Class/Model/LCCKCommonUtils.h b/ChatKit/Class/Model/LCCKCommonUtils.h new file mode 100644 index 0000000..df351bc --- /dev/null +++ b/ChatKit/Class/Model/LCCKCommonUtils.h @@ -0,0 +1,17 @@ +// +// LCCKCommonUtils.h +// AVOSCloud +// +// Created by chenyilong on 14/6/2018. +// + +#import +@class AVFile; + +@interface LCCKCommonUtils : NSObject + ++ (NSString *)getPathFromFile:(AVFile *)file; + ++ (BOOL)isCacheDataAvailableForFile:(AVFile *)file; + +@end diff --git a/ChatKit/Class/Model/LCCKCommonUtils.m b/ChatKit/Class/Model/LCCKCommonUtils.m new file mode 100644 index 0000000..8483e2c --- /dev/null +++ b/ChatKit/Class/Model/LCCKCommonUtils.m @@ -0,0 +1,29 @@ +// +// LCCKCommonUtils.m +// AVOSCloud +// +// Created by chenyilong on 14/6/2018. +// + +#import "LCCKCommonUtils.h" +#import + +@implementation LCCKCommonUtils + ++ (NSString *)getPathFromFile:(AVFile *)file { + NSString *localPath = [file persistentCachePath]; + return localPath; +} + ++ (BOOL)isCacheDataAvailableForFile:(AVFile *)file { + NSString *objectId = file.objectId; + NSString *localPath = [self getPathFromFile:file]; + localPath = (localPath.length > 0) ? localPath :@""; + BOOL fileExistsAtPath = ([[NSFileManager defaultManager] fileExistsAtPath:localPath]); + if (objectId.length > 0 && fileExistsAtPath) { + return YES; + } + return NO; +} + +@end diff --git a/ChatKit/Class/Model/LCCKMessage.m b/ChatKit/Class/Model/LCCKMessage.m index e12f228..22e6299 100755 --- a/ChatKit/Class/Model/LCCKMessage.m +++ b/ChatKit/Class/Model/LCCKMessage.m @@ -18,6 +18,7 @@ #import "UIImage+LCCKExtension.h" //#define LCCKIsDebugging 1 #import "NSObject+LCCKExtension.h" +#import "LCCKCommonUtils.h" @interface LCCKMessage() @@ -304,9 +305,10 @@ + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message { NSString *duration = [NSString stringWithFormat:@"%.0f", audioMsg.duration]; NSString *voicePath; NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *pathForFile = audioMsg.file.localPath; + NSString *localPath = [LCCKCommonUtils getPathFromFile:audioMsg.file]; + NSString *pathForFile = localPath; if ([fileManager fileExistsAtPath:pathForFile]){ - voicePath = audioMsg.file.localPath; + voicePath = localPath; } else { voicePath = audioMsg.file.url; } @@ -325,23 +327,15 @@ + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message { } case kAVIMMessageMediaTypeImage: { AVIMImageMessage *imageMsg = (AVIMImageMessage *)message; - NSString *pathForFile = imageMsg.file.localPath; + NSString *pathForFile = [LCCKCommonUtils getPathFromFile:imageMsg.file];; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *imagePath; if ([fileManager fileExistsAtPath:pathForFile]){ - imagePath = imageMsg.file.localPath; + imagePath = pathForFile; } lcckMessage = [[LCCKMessage alloc] initWithPhoto:nil photoWidth:imageMsg.width photoHeight: imageMsg.height thumbnailPhoto:nil photoPath:imagePath thumbnailURL:nil originPhotoURL:[NSURL URLWithString:imageMsg.file.url] senderId:senderId sender:sender timestamp:time serverMessageId:serverMessageId]; break; } - - //#import "AVIMEmotionMessage.h" - // case kAVIMMessageMediaTypeEmotion: { - // AVIMEmotionMessage *emotionMsg = (AVIMEmotionMessage *)message; - // NSString *path = [[NSBundle mainBundle] pathForResource:emotionMsg.emotionPath ofType:@"gif"]; - // lcckMessage = [[LCCKMessage alloc] initWithEmotionPath:path sender:sender timestamp:time]; - // break; - // } case kAVIMMessageMediaTypeVideo: { //TODO: break; diff --git a/ChatKit/Class/Module/ContactList/Controller/LCCKContactListViewController.m b/ChatKit/Class/Module/ContactList/Controller/LCCKContactListViewController.m index ad3540d..c04746a 100644 --- a/ChatKit/Class/Module/ContactList/Controller/LCCKContactListViewController.m +++ b/ChatKit/Class/Module/ContactList/Controller/LCCKContactListViewController.m @@ -326,7 +326,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - LCCKContactCell *cell = [tableView dequeueReusableCellWithIdentifier:LCCKContactListViewControllerIdentifier forIndexPath:indexPath]; + LCCKContactCell *cell = [tableView dequeueReusableCellWithIdentifier:LCCKContactListViewControllerIdentifier]; id contact = [self contactAtIndexPath:indexPath tableView:tableView]; NSURL *avatarURL = nil; NSString *name = nil; diff --git a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m index a757975..b9790b0 100644 --- a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m +++ b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m @@ -206,7 +206,7 @@ - (LCCKConversationViewModel *)chatViewModel { - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userWillSendMsgWithoutPower) name:LCCKNotificationRecordNoPower object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveNewMsgForLengthOut) name:LCCKNotificationTextLengthOut object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveNewMsgForLengthOut) name:LCCKNotificationTextLengthOut object:nil]; __unsafe_unretained __typeof(self) weakSelf = self; [self cyl_executeAtDealloc:^{ @@ -273,9 +273,6 @@ - (void)viewDidDisappear:(BOOL)animated { }); } //TODO: 群聊人数改变,改群名称 - // if (self.conversation.members.count > 2) { - // self.navigationItem.titleView = nil; - // } !self.viewDidDisappearBlock ?: self.viewDidDisappearBlock(self, animated); } @@ -338,7 +335,7 @@ - (void)sendImageMessageData:(NSData *)imageData { } - (void)sendVoiceMessageWithPath:(NSString *)voicePath time:(NSTimeInterval)recordingSeconds { - + LCCKMessage *message = [[LCCKMessage alloc] initWithVoicePath:voicePath voiceURL:nil voiceDuration:[NSString stringWithFormat:@"%@", @(recordingSeconds)] @@ -351,7 +348,7 @@ - (void)sendVoiceMessageWithPath:(NSString *)voicePath time:(NSTimeInterval)reco } - (void)sendLocationMessageWithLocationCoordinate:(CLLocationCoordinate2D)locationCoordinate locatioTitle:(NSString *)locationTitle { - + LCCKMessage *message = [[LCCKMessage alloc] initWithLocalPositionPhoto:({ NSString *imageName = @"message_sender_location"; UIImage *image = [UIImage lcck_imageNamed:imageName bundleName:@"MessageBubble" bundleForClass:[self class]]; @@ -564,8 +561,8 @@ - (void)refreshConversation:(AVIMConversation *)aConversation isJoined:(BOOL)isJ //peer初始化成功时也会对conversation赋值 _conversation = conversation; [self saveCurrentConversationInfoIfExists]; -// if (_conversation) { -// } + // if (_conversation) { + // } [self callbackCurrentConversationEvenNotExists:conversation callback:^(BOOL succeeded, NSError *error) { if (succeeded) { [self handleLoadHistoryMessagesHandlerIfIsJoined:isJoined]; @@ -840,21 +837,6 @@ - (void)messageCellTappedMessage:(LCCKChatMessageCell *)messageCell { } break; default: { -// //TODO:自定义消息的点击事件 -// NSString *formatString = @"\n\n\ -// ------ BEGIN NSException Log ---------------\n \ -// class name: %@ \n \ -// ------line: %@ \n \ -// ----reason: %@ \n \ -// ------ END -------------------------------- \n\n"; -// NSString *reason = [NSString stringWithFormat:formatString, -// @(__PRETTY_FUNCTION__), -// @(__LINE__), -// @"messageCell.messageType not handled"]; -// //手动创建一个异常导致的崩溃事件 http://is.gd/EfVfN0 -// @throw [NSException exceptionWithName:NSGenericException -// reason:reason -// userInfo:nil]; } break; } @@ -1009,31 +991,30 @@ - (void)updateStatusView { self.clientStatusView.hidden = NO; } } - - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} - #pragma mark - Notification +#pragma mark - Notification - - (void)userWillSendMsgWithoutPower { - [self showWaring:@"需要开启麦克风权限"]; - } +- (void)userWillSendMsgWithoutPower { + [self showWaring:@"需要开启麦克风权限"]; +} - (void)recieveNewMsgForLengthOut { NSString *message = [NSString stringWithFormat:@"每次输入最多%@字~", @(LCCKNotificationTextLengthOutLength)]; [self showWaring:message]; } - - (void)showWaring:(NSString *)message { - // 没有找到Toast 只能用弹框 - LCCKAlertController *alert = [LCCKAlertController alertControllerWithTitle:nil - message:message - preferredStyle:LCCKAlertControllerStyleAlert]; - NSString *cancelActionTitle = LCCKLocalizedStrings(@"ok"); - LCCKAlertAction *cancelAction = [LCCKAlertAction actionWithTitle:cancelActionTitle style:LCCKAlertActionStyleDefault - handler:^(LCCKAlertAction * action) {}]; - [alert addAction:cancelAction]; - [alert showWithSender:nil controller:self animated:YES completion:NULL]; - } +- (void)showWaring:(NSString *)message { + LCCKAlertController *alert = [LCCKAlertController alertControllerWithTitle:nil + message:message + preferredStyle:LCCKAlertControllerStyleAlert]; + NSString *cancelActionTitle = LCCKLocalizedStrings(@"ok"); + LCCKAlertAction *cancelAction = [LCCKAlertAction actionWithTitle:cancelActionTitle style:LCCKAlertActionStyleDefault + handler:^(LCCKAlertAction * action) {}]; + [alert addAction:cancelAction]; + [alert showWithSender:nil controller:self animated:YES completion:NULL]; +} @end diff --git a/ChatKit/Class/Module/Conversation/Model/LCCKConversationViewModel.m b/ChatKit/Class/Module/Conversation/Model/LCCKConversationViewModel.m index e1a1068..9f1670d 100644 --- a/ChatKit/Class/Module/Conversation/Model/LCCKConversationViewModel.m +++ b/ChatKit/Class/Module/Conversation/Model/LCCKConversationViewModel.m @@ -515,7 +515,7 @@ - (void)sendMessage:(id)aMessage !success ?: success(succeeded, nil); } // cache file type messages even failed - [LCCKConversationService cacheFileTypeMessages:@[avimTypedMessage] callback:nil]; + [LCCKConversationService cacheFileTypeMessagesInBackground:@[avimTypedMessage]]; }]; }; @@ -689,12 +689,13 @@ - (void)queryAndCacheMessagesWithTimestamp:(int64_t)timestamp !block ?: block(avimTypedMessages, error); return; } - [LCCKConversationService cacheFileTypeMessages:avimTypedMessages callback:^(BOOL succeeded, NSError *error) { + [LCCKConversationService cacheFileTypeMessagesInBackground:avimTypedMessages]; + dispatch_async(dispatch_get_main_queue(),^{ if (avimTypedMessages.count < kLCCKOnePageSize) { self.parentConversationViewController.shouldLoadMoreMessagesScrollToTop = NO; } !block ?: block(avimTypedMessages, error); - }]; + }); }]; } @@ -727,7 +728,10 @@ - (void)insertOldMessages:(NSArray *)oldMessages completion:(void (^)())completi dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { NSMutableArray *messages = [NSMutableArray arrayWithArray:oldMessages]; [messages addObjectsFromArray:self.dataArray]; - CGSize beforeContentSize = self.parentConversationViewController.tableView.contentSize; + __block CGSize beforeContentSize; + dispatch_async(dispatch_get_main_queue(),^{ + beforeContentSize = self.parentConversationViewController.tableView.contentSize; + }); NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:oldMessages.count]; [oldMessages enumerateObjectsUsingBlock:^(id message, NSUInteger idx, BOOL *stop) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; diff --git a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m index 2aafa48..442bb0e 100755 --- a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m +++ b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m @@ -98,7 +98,6 @@ - (void)configureCellWithData:(LCCKMessage *)message { CGSize photoSize = CGSizeMake(message.photoWidth, message.photoHeight); UIImage *newImage = [image lcck_imageByScalingAspectFillWithOriginSize:photoSize]; self.messageImageView.contentMode = UIViewContentModeScaleAspectFit; - UIEdgeInsets edgeMessageBubbleCustomize; if (message.ownerType == LCCKMessageOwnerTypeSelf) { UIEdgeInsets rightEdgeMessageBubbleCustomize = [LCCKSettingService sharedInstance].rightHollowEdgeMessageBubbleCustomize; @@ -114,7 +113,7 @@ - (void)configureCellWithData:(LCCKMessage *)message { make.height.mas_equalTo(newImage.size.height); make.width.mas_equalTo(newImage.size.width); }]; - }else { + } else { [self.messageImageView mas_updateConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.messageContentView).with.insets(edgeMessageBubbleCustomize); make.height.mas_equalTo(newImage.size.height); @@ -122,23 +121,21 @@ - (void)configureCellWithData:(LCCKMessage *)message { }]; } - [self.messageImageView sd_setImageWithURL:message.originPhotoURL placeholderImage:newImage - completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { - dispatch_async(dispatch_get_main_queue(),^{ - if (image){ - message.photo = image; - message.thumbnailPhoto = [image lcck_imageByScalingAspectFillWithOriginSize:photoSize]; - if ([self.delegate respondsToSelector:@selector(fileMessageDidDownload:)]) { - [self.delegate fileMessageDidDownload:self]; - } - } - }); - - } + [self.messageImageView sd_setImageWithURL:message.originPhotoURL placeholderImage:newImage + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + dispatch_async(dispatch_get_main_queue(),^{ + if (image){ + message.photo = image; + message.thumbnailPhoto = [image lcck_imageByScalingAspectFillWithOriginSize:photoSize]; + if ([self.delegate respondsToSelector:@selector(fileMessageDidDownload:)]) { + [self.delegate fileMessageDidDownload:self]; + } + } + }); + } ]; break; } - } while (NO); } diff --git a/ChatKit/Class/Tool/Service/LCCKConversationService.h b/ChatKit/Class/Tool/Service/LCCKConversationService.h index 3f8c0f5..8286555 100644 --- a/ChatKit/Class/Tool/Service/LCCKConversationService.h +++ b/ChatKit/Class/Tool/Service/LCCKConversationService.h @@ -189,7 +189,7 @@ FOUNDATION_EXTERN NSString *const LCCKConversationServiceErrorDomain; - (NSArray *)failedMessagesByMessageIds:(NSArray *)messageIds; -+ (void)cacheFileTypeMessages:(NSArray *)messages callback:(AVBooleanResultBlock)callback; ++ (void)cacheFileTypeMessagesInBackground:(NSArray *)messages; @end diff --git a/ChatKit/Class/Tool/Service/LCCKConversationService.m b/ChatKit/Class/Tool/Service/LCCKConversationService.m index 1a80082..fc72baf 100644 --- a/ChatKit/Class/Tool/Service/LCCKConversationService.m +++ b/ChatKit/Class/Tool/Service/LCCKConversationService.m @@ -24,6 +24,7 @@ #import "LCCKMessage.h" #import "LCCKConversationListService.h" #import "AVIMMessage+LCCKExtension.h" +#import "LCCKCommonUtils.h" NSString *const LCCKConversationServiceErrorDomain = @"LCCKConversationServiceErrorDomain"; @@ -745,42 +746,22 @@ - (void)queryTypedMessagesWithConversation:(AVIMConversation *)conversation }); } -+ (void)cacheFileTypeMessages:(NSArray *)messages callback:(AVBooleanResultBlock)callback { - NSString *queueBaseLabel = [NSString stringWithFormat:@"com.chatkit.%@", NSStringFromClass([self class])]; - const char *queueName = [[NSString stringWithFormat:@"%@.ForBarrier",queueBaseLabel] UTF8String]; - dispatch_queue_t queue = dispatch_queue_create(queueName, DISPATCH_QUEUE_CONCURRENT); - ++ (void)cacheFileTypeMessagesInBackground:(NSArray *)messages { for (AVIMTypedMessage *message in messages) { - dispatch_async(queue, ^(void) { - if (message.mediaType == kAVIMMessageMediaTypeImage || message.mediaType == kAVIMMessageMediaTypeAudio) { - AVFile *file = message.file; - if (file && file.isDataAvailable == NO) { - NSError *error; - // 下载到本地 - NSData *data = [file getData:&error]; - if (error || data == nil) { - LCCKLog(@"download file error : %@", error); - } - } - } else if (message.mediaType == kAVIMMessageMediaTypeVideo) { - NSString *path = [[LCCKSettingService sharedInstance] videoPathOfMessage:(AVIMVideoMessage *)message]; - if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { - NSError *error; - NSData *data = [message.file getData:&error]; + if (message.mediaType == kAVIMMessageMediaTypeImage || message.mediaType == kAVIMMessageMediaTypeAudio) { + AVFile *file = message.file; + BOOL isDataAvailable = [LCCKCommonUtils isCacheDataAvailableForFile:file]; + if (file && !isDataAvailable) { + NSError *error; + // 下载到本地 + [file downloadWithCompletionHandler:^(NSURL * _Nullable filePath, NSError * _Nullable error) { if (error) { LCCKLog(@"download file error : %@", error); - } else { - [data writeToFile:path atomically:YES]; } - } + }]; } - }); + } } - dispatch_barrier_async(queue, ^{ - dispatch_async(dispatch_get_main_queue(),^{ - !callback ?: callback(YES, nil); - }); - }); } - (AVIMClient *)client { diff --git a/ChatKit/Class/Tool/Service/LCCKSessionService.m b/ChatKit/Class/Tool/Service/LCCKSessionService.m index 761cc6b..3fec724 100644 --- a/ChatKit/Class/Tool/Service/LCCKSessionService.m +++ b/ChatKit/Class/Tool/Service/LCCKSessionService.m @@ -72,8 +72,11 @@ - (void)openWithClientId:(NSString *)clientId force:(BOOL)force callback:(AVIMBo if ([[LCChatKit sharedInstance] generateSignatureBlock]) { _client.signatureDataSource = self; } - AVIMClientOpenOption *option = [AVIMClientOpenOption new]; - option.force = force; + + AVIMClientOpenOption option = AVIMClientOpenOptionReopen; + if (force) { + option = AVIMClientOpenOptionForceOpen; + } [_client openWithOption:option callback:^(BOOL succeeded, NSError *error) { [self updateConnectStatus];