Commit 900d470d authored by 翟书觅's avatar 翟书觅

iCloud无法同步逻辑优化

parent 11938e72
......@@ -823,7 +823,7 @@
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = LTFQDC2QVX;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/TZImagePickerController",
......
......@@ -169,12 +169,16 @@
_bigImageRequestID = [[TZImageManager manager] requestImageDataForAsset:_model.asset completion:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
if (!imageData && [info[PHImageResultIsInCloudKey] boolValue]) {
self.model.iCloudFaile = YES;
if (self.model.type == TZAssetModelMediaTypeVideo ||
self.model.type == TZAssetCellTypePhotoGif ||
self.model.type == TZAssetModelMediaTypeLivePhoto) {
self.model.iCloudFailed = YES;
if (self.didSelectPhotoBlock) {
self.didSelectPhotoBlock(YES);
self.selectImageView.image = self.photoDefImage;
}
}
}
[self hideProgressView];
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
if (self.model.isSelected) {
......
......@@ -24,7 +24,7 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No
@property (nonatomic, assign) TZAssetModelMediaType type;
@property (nonatomic, copy) NSString *timeLength;
@property (nonatomic, assign) BOOL iCloudFaile;
@property (nonatomic, assign) BOOL iCloudFailed;
/// Init a photo dataModel With a PHAsset
/// 用一个PHAsset实例,初始化一个照片模型
......
......@@ -566,11 +566,15 @@ static CGFloat itemMargin = 5;
[[NSNotificationCenter defaultCenter] postNotificationName:@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION" object:strongSelf.navigationController];
}
[UIView showOscillatoryAnimationWithLayer:strongLayer type:TZOscillatoryAnimationToSmaller];
if (strongCell.model.iCloudFaile) {
if (strongCell.model.type == TZAssetModelMediaTypeLivePhoto ||
strongCell.model.type == TZAssetModelMediaTypePhotoGif ||
strongCell.model.type == TZAssetModelMediaTypeVideo) {
if (strongCell.model.iCloudFailed) {
[strongSelf->_models replaceObjectAtIndex:indexPath.item withObject:strongCell.model];
NSString *title = [NSBundle tz_localizedStringForKey:@"iCloud sync failed"];
[tzImagePickerVc showAlertWithTitle:title];
}
}
} else {
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) {
......
......@@ -40,6 +40,7 @@
@property (nonatomic, strong) TZProgressView *progressView;
@property (nonatomic, strong) UIImageView *icloudErrorIcon;
@property (nonatomic, strong) UILabel *icloudErrorLB;
@property (nonatomic, copy) void (^iCloudSyncFailed)(id asset, BOOL isSyncFailed);
@property (nonatomic, assign) BOOL allowCrop;
......@@ -65,6 +66,7 @@
@property (nonatomic, strong) NSURL *videoURL;
@property (nonatomic, strong) UIImageView *icloudErrorIcon;
@property (nonatomic, strong) UILabel *icloudErrorLB;
@property (nonatomic, copy) void (^iCloudSyncFailed)(id asset, BOOL isSyncFailed);
- (void)pausePlayerAndShowNaviBar;
@end
......
......@@ -67,6 +67,7 @@
- (void)setModel:(TZAssetModel *)model {
[super setModel:model];
_previewView.asset = model.asset;
_previewView.model = model;
}
- (void)recoverSubviews {
......@@ -177,7 +178,12 @@
self->_icloudErrorLB.hidden = YES;
self->_icloudErrorIcon.hidden = YES;
}
if (self.iCloudSyncFailed) {
self.iCloudSyncFailed(model.asset, !self->_icloudErrorLB.hidden);
}
if (photo) {
self.imageView.image = photo;
}
[self resizeSubviews];
if (self.isRequestingGIF) {
return;
......@@ -222,6 +228,9 @@
_asset = asset;
self.imageRequestID = [[TZImageManager manager] getPhotoWithAsset:asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (self.model.type == TZAssetModelMediaTypeVideo ||
self.model.type ==TZAssetModelMediaTypePhotoGif ||
self.model.type == TZAssetModelMediaTypeLivePhoto) {
if (!photo && [info[PHImageResultIsInCloudKey] boolValue]) {
self->_icloudErrorLB.hidden = NO;
self->_icloudErrorIcon.hidden = NO;
......@@ -229,8 +238,14 @@
self->_icloudErrorLB.hidden = YES;
self->_icloudErrorIcon.hidden = YES;
}
if (self.iCloudSyncFailed) {
self.iCloudSyncFailed(asset, !self->_icloudErrorLB.hidden);
}
}
if (![asset isEqual:self->_asset]) return;
if (photo) {
self.imageView.image = photo;
}
[self resizeSubviews];
if (self.imageView.tz_height && self.allowCrop) {
CGFloat scale = MAX(self.cropRect.size.width / self.imageView.tz_width, self.cropRect.size.height / self.imageView.tz_height);
......@@ -447,7 +462,12 @@
self->_icloudErrorLB.hidden = YES;
self->_icloudErrorIcon.hidden = YES;
}
if (self.iCloudSyncFailed) {
self.iCloudSyncFailed(self.model.asset, !self->_icloudErrorLB.hidden);
}
if (photo) {
self.cover = photo;
}
}];
[[TZImageManager manager] getVideoWithAsset:self.model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{
......
......@@ -459,8 +459,18 @@
__weak typeof(self) weakSelf = self;
if (_tzImagePickerVc.allowPickingMultipleVideo && model.type == TZAssetModelMediaTypeVideo) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZVideoPreviewCell" forIndexPath:indexPath];
TZVideoPreviewCell *currentCell = (TZVideoPreviewCell *)cell;
currentCell.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
model.iCloudFailed = isSyncFailed;
[weakSelf.models replaceObjectAtIndex:indexPath.item withObject:model];
};
} else if (_tzImagePickerVc.allowPickingMultipleVideo && model.type == TZAssetModelMediaTypePhotoGif && _tzImagePickerVc.allowPickingGif) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZGifPreviewCell" forIndexPath:indexPath];
TZGifPreviewCell *currentCell = (TZGifPreviewCell *)cell;
currentCell.previewView.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
model.iCloudFailed = isSyncFailed;
[weakSelf.models replaceObjectAtIndex:indexPath.item withObject:model];
};
} else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZPhotoPreviewCell" forIndexPath:indexPath];
TZPhotoPreviewCell *photoPreviewCell = (TZPhotoPreviewCell *)cell;
......@@ -485,6 +495,10 @@
}
}
}];
photoPreviewCell.previewView.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
model.iCloudFailed = isSyncFailed;
[weakSelf.models replaceObjectAtIndex:indexPath.item withObject:model];
};
}
cell.model = model;
......@@ -563,51 +577,79 @@
_originalPhotoLabel.hidden = YES;
_doneButton.hidden = YES;
}
// iCLoud同步失败的UI刷新
if (model.type == TZAssetModelMediaTypePhotoGif ||
model.type == TZAssetModelMediaTypeLivePhoto ||
model.type == TZAssetModelMediaTypeVideo) {
[self refreshiCloudFailed:model];
}
if (_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock) {
_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock(_collectionView, _naviBar, _backButton, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
}
}
- (void)refreshSelectButtonImageViewContentMode {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self->_selectButton.imageView.image.size.width <= 27) {
self->_selectButton.imageView.contentMode = UIViewContentModeCenter;
} else {
self->_selectButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
});
}
- (void)refreshiCloudFailed:(TZAssetModel *)model{
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (model.iCloudFailed) {
_selectButton.hidden = YES;
_originalPhotoButton.hidden = YES;
_originalPhotoLabel.hidden = YES;
if (_tzImagePickerVc.selectedModels.count <= 0) {
_doneButton.enabled = !model.iCloudFailed;
}else{
_doneButton.enabled = YES;
}
}else{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.currentIndex inSection:0];
UICollectionViewCell *cell = [_collectionView cellForItemAtIndexPath:indexPath];
if ([cell isKindOfClass:[TZPhotoPreviewCell class]]) {
TZPhotoPreviewCell *currentCell = (TZPhotoPreviewCell *)cell;
currentCell.previewView.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
if ([asset isEqual:model.asset]) {
if (_tzImagePickerVc.selectedModels.count <= 0) {
_doneButton.enabled = currentCell.previewView.icloudErrorLB.hidden;
self->_doneButton.enabled = !isSyncFailed;
} else {
_doneButton.enabled = YES;
self->_doneButton.enabled = YES;
}
_selectButton.hidden = !currentCell.previewView.icloudErrorLB.hidden;
self->_selectButton.hidden = isSyncFailed;
}
};
} else if([cell isKindOfClass:[TZVideoPreviewCell class]]){
TZVideoPreviewCell *currentCell = (TZVideoPreviewCell *)cell;
currentCell.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
if ([asset isEqual:model.asset]) {
if (_tzImagePickerVc.selectedModels.count <= 0) {
_doneButton.enabled = currentCell.icloudErrorLB.hidden;
self->_doneButton.enabled = !isSyncFailed;
} else {
_doneButton.enabled = YES;
self->_doneButton.enabled = YES;
}
self->_selectButton.hidden = isSyncFailed;
}
_selectButton.hidden = !currentCell.icloudErrorLB.hidden;
};
} else if ([cell isKindOfClass:[TZGifPreviewCell class]]){
TZGifPreviewCell *currentCell = (TZGifPreviewCell *)cell;
currentCell.previewView.iCloudSyncFailed = ^(id asset, BOOL isSyncFailed) {
if ([asset isEqual:model.asset]) {
if (_tzImagePickerVc.selectedModels.count <= 0) {
_doneButton.enabled = currentCell.previewView.icloudErrorLB.hidden;
self->_doneButton.enabled = !isSyncFailed;
} else {
_doneButton.enabled = YES;
self->_doneButton.enabled = YES;
}
_selectButton.hidden = !currentCell.previewView.icloudErrorLB.hidden;
self->_selectButton.hidden = isSyncFailed;
}
if (model.iCloudFaile) {
_selectButton.hidden = YES;
_doneButton.enabled = NO;
}
if (_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock) {
_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock(_collectionView, _naviBar, _backButton, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
};
}
}
- (void)refreshSelectButtonImageViewContentMode {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self->_selectButton.imageView.image.size.width <= 27) {
self->_selectButton.imageView.contentMode = UIViewContentModeCenter;
} else {
self->_selectButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
});
}
- (void)showPhotoBytes {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment