Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现一个崩溃bug #51

Closed
CHENDONGY opened this issue Oct 17, 2017 · 1 comment
Closed

发现一个崩溃bug #51

CHENDONGY opened this issue Oct 17, 2017 · 1 comment

Comments

@CHENDONGY
Copy link

CHENDONGY commented Oct 17, 2017

当我我设置只是选择照片时,设置最大选择9张,当选择9之后,照片后面的选择按钮消失,点击最后一张图删除崩溃,崩溃位置HXPhotoTools.m

+ (void)getSelectedListResultModel:(NSArray<HXPhotoModel *> *)selectedList complete:(void (^)(NSArray<HXPhotoResultModel *> *, NSArray<HXPhotoResultModel *> *, NSArray<HXPhotoResultModel *> *))complete {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSMutableArray *models = [NSMutableArray array];
        NSMutableArray *photos = [NSMutableArray array];
        NSMutableArray *videos = [NSMutableArray array];
        
        for (HXPhotoModel *photoModel in selectedList) {
            HXPhotoResultModel *resultModel = [[HXPhotoResultModel alloc] init];
            resultModel.index = photoModel.endCollectionIndex; // 定位的崩溃位置在这里
            if (photoModel.asset) {
                if (photoModel.subType == HXPhotoModelMediaSubTypeVideo) {
                    if ([photoModel.avAsset isKindOfClass:[AVURLAsset class]]) {
                        AVURLAsset *urlAsset = (AVURLAsset *)photoModel.avAsset;
                        resultModel.videoURL = urlAsset.URL;
                    }
                    resultModel.type = HXPhotoResultModelMediaTypeVideo;
                    resultModel.videoIndex = photoModel.videoIndex;
                }else {
                    resultModel.photoIndex = photoModel.endIndex;
                    resultModel.type = HXPhotoResultModelMediaTypePhoto;
                }
                resultModel.avAsset = photoModel.avAsset;
                PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
                options.networkAccessAllowed = NO;
                __weak typeof(self) weakSelf = self;
                [photoModel.asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
                    BOOL error = [info objectForKey:PHContentEditingInputErrorKey];
                    //            BOOL cloud = [[info objectForKey:PHContentEditingInputResultIsInCloudKey] boolValue];
                    BOOL cancel = [[info objectForKey:PHContentEditingInputCancelledKey] boolValue];
                    
                    if (!error && !cancel && contentEditingInput) {
                        resultModel.fullSizeImageURL = contentEditingInput.fullSizeImageURL;
                        if (resultModel.type == HXPhotoResultModelMediaTypePhoto) {
                            resultModel.displaySizeImage = contentEditingInput.displaySizeImage;
                        }else {
                            resultModel.displaySizeImage = photoModel.thumbPhoto;
                        }
                        resultModel.fullSizeImageOrientation = contentEditingInput.fullSizeImageOrientation;
                        resultModel.creationDate = contentEditingInput.creationDate;
                        resultModel.location = contentEditingInput.location;
                        if ([contentEditingInput.avAsset isKindOfClass:[AVURLAsset class]]) {
                            AVURLAsset *urlAsset = (AVURLAsset *)contentEditingInput.avAsset;
                            resultModel.videoURL = urlAsset.URL;
                            resultModel.avAsset = contentEditingInput.avAsset;
                        }
                        [weakSelf sortResultModel:resultModel total:selectedList.count models:models photos:photos videos:videos completion:^(NSArray *all, NSArray *photos, NSArray *videos) {
                            dispatch_async(dispatch_get_main_queue(), ^{
                                if (complete) {
                                    complete(all,photos,videos);
                                }
                            });
                        }];
                    }
                }];
            }else {
                resultModel.creationDate = [NSDate date];
                resultModel.displaySizeImage = photoModel.previewPhoto;
                if (photoModel.subType == HXPhotoModelMediaSubTypePhoto) {
                    resultModel.photoIndex = photoModel.endIndex;
                    resultModel.type = HXPhotoResultModelMediaTypePhoto;
                    resultModel.fullSizeImageOrientation = photoModel.previewPhoto.imageOrientation;
                    NSData *imageData;
                    NSString *suffix;
                    if (UIImagePNGRepresentation(photoModel.previewPhoto)) {
                        //返回为png图像。
                        imageData = UIImagePNGRepresentation(photoModel.previewPhoto);
                        suffix = @"png";
                    }else {
                        //返回为JPEG图像。
                        imageData = UIImageJPEGRepresentation(photoModel.previewPhoto, 1.0);
                        suffix = @"jpeg";
                    }
                    NSString *fileName = [[self uploadFileName] stringByAppendingString:[NSString stringWithFormat:@".%@",suffix]];
                    NSString *fullPathToFile = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
                    [imageData writeToFile:fullPathToFile atomically:YES];
                    resultModel.fullSizeImageURL = [NSURL fileURLWithPath:fullPathToFile];
                }else {
                    resultModel.videoIndex = photoModel.videoIndex;
                    resultModel.type = HXPhotoResultModelMediaTypeVideo;
                    resultModel.videoURL = photoModel.videoURL;
                }
                [self sortResultModel:resultModel total:selectedList.count models:models photos:photos videos:videos completion:^(NSArray *all, NSArray *photos, NSArray *videos) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (complete) {
                            complete(all,photos,videos);
                        }
                    });
                }];
            }
            
        }
    });
}

@SilenceLove
Copy link
Owner

已经不推荐用这个方法了..可以看看最新版的..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants