1
This commit is contained in:
@@ -336,15 +336,21 @@
|
||||
[p loadObjectOfClass:UIImage.class completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error) {
|
||||
UIImage *img = ([object isKindOfClass:UIImage.class] ? (UIImage *)object : nil);
|
||||
if (!img) return;
|
||||
|
||||
// 这里就在子线程里压缩,避免卡 UI
|
||||
// 比如目标 100KB,你自己改成想要的值
|
||||
NSUInteger targetKB = 50;
|
||||
NSData *compressedData = [weakSelf kb_compressImage:img targetKB:targetKB];
|
||||
if (!compressedData) return;
|
||||
UIImage *compressedImage = [UIImage imageWithData:compressedData];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[weakSelf.myVM upLoadAvatarWithData:compressedData completion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
[KBHUD showError:error.localizedDescription];
|
||||
return;
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
weakSelf.avatarView.image = compressedImage;
|
||||
});
|
||||
|
||||
}];
|
||||
|
||||
});
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user