|
@@ -88,7 +88,7 @@
|
|
|
}else{
|
|
}else{
|
|
|
self.voiceDuration = duration/1000;
|
|
self.voiceDuration = duration/1000;
|
|
|
}
|
|
}
|
|
|
- self.voiceWidth = self.voiceDuration==0?0:[self voiceBubbleWidth];
|
|
|
|
|
|
|
+ self.voiceWidth = [self voiceBubbleWidth];
|
|
|
|
|
|
|
|
//文件传输成功或失败
|
|
//文件传输成功或失败
|
|
|
self.fileError = 0;
|
|
self.fileError = 0;
|
|
@@ -386,224 +386,63 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//下载视频文件
|
|
//下载视频文件
|
|
|
--(void)xiazaishipin:(void(^)(NSInteger persent))loading{
|
|
|
|
|
- NSLog(@"xiazaishipin--------");
|
|
|
|
|
-
|
|
|
|
|
- if(!self.isSender){
|
|
|
|
|
- NSString *localFileurl = [self.localurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
|
|
|
|
|
- if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:localFileurl]){
|
|
|
|
|
-// NSLog(@"文件已经存在本地");
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
-// NSLog(@"文件不存在");
|
|
|
|
|
- if(self.url&&self.url.length != 0){
|
|
|
|
|
-
|
|
|
|
|
- NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
|
|
|
|
|
- NSURL *tempUrl = [NSURL URLWithString:self.url];
|
|
|
|
|
- NSString *fileName = tempUrl.lastPathComponent;
|
|
|
|
|
- NSString *fileExtension = [fileName pathExtension];
|
|
|
|
|
- NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
|
|
|
|
|
- documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
|
|
|
|
|
- NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
|
|
|
|
|
- NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = documentsDirectoryURL.path;
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
|
|
|
|
|
- if(res!=nil){
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:res[@"filePath"] forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = res[@"filePath"];
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if (code>=0&&code<200) {
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(code);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } fail:^(NSError * _Nonnull error) {
|
|
|
|
|
- NSLog(@"error:%@",error);
|
|
|
|
|
- }];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(0);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+-(void)downloadFileIfNeed:(void(^)(NSInteger persent))loading{
|
|
|
|
|
+ NSString *localFileurl = [self.localurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
|
|
|
|
|
+ if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:localFileurl]){
|
|
|
|
|
+ self.customFileSize = [self getFileSize];
|
|
|
|
|
+ if (loading) {
|
|
|
|
|
+ loading(100);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- NSLog(@"downLoadWToken xiazaishipin-----");
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
--(void)xiazaiwenjian:(void(^)(NSInteger persent))loading{
|
|
|
|
|
- NSLog(@"xiazaiwenjian---");
|
|
|
|
|
- if (self.isSender) {
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- else{
|
|
|
|
|
-// NSLog(@"self.localurl2:%@",self.localurl);
|
|
|
|
|
- if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
|
|
|
|
|
-// NSLog(@"文件已经存在本地");
|
|
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if(self.url&&self.url.length != 0){
|
|
|
|
|
-
|
|
|
|
|
- NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
|
|
|
|
|
- NSURL *tempUrl = [NSURL URLWithString:self.url];
|
|
|
|
|
- NSString *fileName = tempUrl.lastPathComponent;
|
|
|
|
|
- NSString *fileExtension = [fileName pathExtension];
|
|
|
|
|
- NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
|
|
|
|
|
- documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
|
|
|
|
|
- NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
|
|
|
|
|
- NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = documentsDirectoryURL.path;
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
|
|
|
|
|
- if(res!=nil){
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:res[@"filePath"] forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = res[@"filePath"];
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if (code>=0&&code<200) {
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(code);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } fail:^(NSError * _Nonnull error) {
|
|
|
|
|
- NSLog(@"error:%@",error);
|
|
|
|
|
- }];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(0);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
|
|
|
|
|
+ NSURL *tempUrl = [NSURL URLWithString:self.url];
|
|
|
|
|
+ NSString *fileName = tempUrl.lastPathComponent;
|
|
|
|
|
+ NSString *fileExtension = [fileName pathExtension];
|
|
|
|
|
+ NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
|
|
|
|
|
+ documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
|
|
|
|
|
+ NSLog(@"文件本地路径:%@",documentsDirectoryURL.path);
|
|
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
|
|
|
|
|
+ NSLog(@"文件已经存在本地");
|
|
|
|
|
+ NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
+ NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
+ [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
|
|
|
|
|
+ [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
+ self.localurl = documentsDirectoryURL.path;
|
|
|
|
|
+ NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
+ [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
+ self.customFileSize = [self getFileSize];
|
|
|
|
|
+ if (loading) {
|
|
|
|
|
+ loading(100);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
--(void)xiazaiyuyin:(void(^)(NSInteger persent))loading{
|
|
|
|
|
- NSLog(@"xiazaiwenjian---");
|
|
|
|
|
- if (self.isSender) {
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- else{
|
|
|
|
|
-// NSLog(@"self.localurl2:%@",self.localurl);
|
|
|
|
|
- if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
|
|
|
|
|
-// NSLog(@"文件已经存在本地");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
|
|
|
|
|
+ if(res!=nil){
|
|
|
|
|
+ NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
+ NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
+ [extend setObject:res[@"filePath"] forKey:@"localurl"];
|
|
|
|
|
+ [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
+ self.localurl = res[@"filePath"];
|
|
|
|
|
+ NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
+ [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
+ self.customFileSize = [self getFileSize];
|
|
|
if (loading) {
|
|
if (loading) {
|
|
|
loading(100);
|
|
loading(100);
|
|
|
}
|
|
}
|
|
|
- return;
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if(self.url&&self.url.length != 0){
|
|
|
|
|
-
|
|
|
|
|
- NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
|
|
|
|
|
- NSURL *tempUrl = [NSURL URLWithString:self.url];
|
|
|
|
|
- NSString *fileName = tempUrl.lastPathComponent;
|
|
|
|
|
- NSString *fileExtension = [fileName pathExtension];
|
|
|
|
|
- NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
|
|
|
|
|
- documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
|
|
|
|
|
- NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
|
|
|
|
|
- NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = documentsDirectoryURL.path;
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
|
|
+ else{
|
|
|
|
|
+ if (code>=0&&code<200) {
|
|
|
if (loading) {
|
|
if (loading) {
|
|
|
- loading(100);
|
|
|
|
|
|
|
+ loading(code);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- else{
|
|
|
|
|
- [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
|
|
|
|
|
- if(res!=nil){
|
|
|
|
|
- NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
|
|
|
|
|
- NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
|
|
|
|
|
- [extend setObject:res[@"filePath"] forKey:@"localurl"];
|
|
|
|
|
- [mutableDict setObject:extend forKey:@"extend"];
|
|
|
|
|
- self.localurl = res[@"filePath"];
|
|
|
|
|
- NSDictionary *NewMsg = [mutableDict copy];
|
|
|
|
|
- [ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if (code>=0&&code<200) {
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(code);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } fail:^(NSError * _Nonnull error) {
|
|
|
|
|
- NSLog(@"error:%@",error);
|
|
|
|
|
- }];
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
- else{
|
|
|
|
|
- if (loading) {
|
|
|
|
|
- loading(0);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ } fail:^(NSError * _Nonnull error) {
|
|
|
|
|
+ NSLog(@"downLoadWToken error:%@",error);
|
|
|
|
|
+ }];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|