Skip to content

Commit

Permalink
Merge pull request #174 from zjc19891106/main
Browse files Browse the repository at this point in the history
fix username empty
  • Loading branch information
lixm1988 authored Apr 13, 2023
2 parents 701b2d6 + 4e6e4ae commit 562aa88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 52 deletions.
2 changes: 1 addition & 1 deletion EaseIMKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/easemob/easeui_ios.git', :tag => 'EaseIMKit_4.0.1'}
s.frameworks = 'UIKit'
s.libraries = 'stdc++'
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '11.0'
s.source_files = [
'EaseIMKit/EaseIMKit/EaseIMKit.h',
'EaseIMKit/EaseIMKit/EasePublicHeaders.h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,59 +102,18 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
}
[self _sendVideoAction:mp4];
} else {
NSURL *url = info[UIImagePickerControllerReferenceURL];
if (url == nil) {
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil];
PHAssetCollection *collection = fetchResult.firstObject;
PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
PHAsset *asset = assetResult.firstObject;
NSString *localIdentifier = asset.localIdentifier;
PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil];
if(result.count == 0){
[EaseAlertController showErrorAlert:@"无权访问该相册"];
} else {
UIImage *orgImage = info[UIImagePickerControllerOriginalImage];
NSData *data = UIImageJPEGRepresentation(orgImage, 1);
[self _sendImageDataAction:data];
} else {
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0f) {
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
if(result.count == 0){
[EaseAlertController showErrorAlert:@"无权访问该相册"];
}else{
for (PHAsset *asset in result) {
NSArray <PHAssetResource *>*resources = [PHAssetResource assetResourcesForAsset:asset];
if (resources.count > 0) {
if ([resources.firstObject.uniformTypeIdentifier isEqualToString:@"public.png"]) {
NSMutableData *imgData = [[NSMutableData alloc]init];
[PHAssetResourceManager.defaultManager requestDataForAssetResource:resources.firstObject options:nil dataReceivedHandler:^(NSData * _Nonnull data) {
if (data.length > 0) {
[imgData appendData:data];
}
} completionHandler:^(NSError * _Nullable error) {
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
[EaseAlertController showErrorAlert:[error localizedDescription]];
});
} else {
[self _sendImageDataAction:[imgData copy]];
}
}];
} else {
[PHImageManager.defaultManager requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
if (imageData != nil) {
[self _sendImageDataAction:imageData];
} else {
[EaseAlertController showErrorAlert:EaseLocalizableString(@"imageTooLarge", nil)];
}
}];
}
}
}
}
} else {
ALAssetsLibrary *alasset = [[ALAssetsLibrary alloc] init];
[alasset assetForURL:url resultBlock:^(ALAsset *asset) {
if (asset) {
ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc((size_t)[assetRepresentation size]);
NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
NSData *fileData = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
[self _sendImageDataAction:fileData];
}
} failureBlock:NULL];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ - (void)setModel:(EaseMessageModel *)model
}
}
if (model.type != EMChatTypeChat) {
if (model.userDataDelegate && [model.userDataDelegate respondsToSelector:@selector(showName)]) {
if (model.userDataDelegate && [model.userDataDelegate respondsToSelector:@selector(showName)] && ![model.userDataDelegate.showName isEqualToString:@""]) {
self.nameLabel.text = model.userDataDelegate.showName;
} else {
self.nameLabel.text = model.message.from;
Expand Down

0 comments on commit 562aa88

Please sign in to comment.