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

iCloud无法同步逻辑优化

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