iOS - 从照片相册中删除该自定义文件夹后,无法将图像保存到自定义文件夹中

时间:2016-05-12 06:50:04

标签: ios objective-c alassetslibrary

我想将图片保存到 iPhone 中的自定义文件夹中。我已经做了。

但我面临一个奇怪的问题,当我运行我的代码时,它工作正常。但是,当我从iPhone删除该自定义文件夹,然后再次运行我的代码时,不会创建自定义文件夹。

如果我在代码中更改自定义文件夹名称,则使用新名称创建它。但是,即使用户删除了该自定义文件夹,我也希望创建相同的文件夹名称。我不想创建另一个自定义文件夹。

我的代码:

@interface CameraVC () 
{

    ALAssetsLibrary* library;
    GPUImageStillCamera *videoCamera;

}

- (IBAction)clickPhotoBtn:(id)sender {
if (!isCameraPermissionAccessed) {
    [self showAccessDeinedMessage :@"Camera permission denied" withMessage:@"To enable, please go to settings and allow camera permission for this app."];
    return;
}
[videoCamera capturePhotoAsJPEGProcessedUpToFilter:filter withCompletionHandler:^(NSData *processedJPEG, NSError *error){
    if (error!=nil)
    {
        [self showErrorMessage:@"Unable to capture image" ];
        return ;
    }

    else {
         UIImage *image = [UIImage imageWithData:processedJPEG];
        CGFloat zoomReciprocal = 1.0f /currentScale;
        CGPoint offset = CGPointMake(image.size.width * ((1.0f - zoomReciprocal) / 2.0f), image.size.height * ((1.0f - zoomReciprocal) / 2.0f));
        CGRect croppedRect = CGRectMake(offset.x, offset.y, image.size.width * zoomReciprocal, image.size.height * zoomReciprocal);
        CGImageRef croppedImageRef = CGImageCreateWithImageInRect([image CGImage], croppedRect);
        UIImage *croppedImage = [[UIImage alloc] initWithCGImage:croppedImageRef scale:[image scale] orientation:[image imageOrientation]];
        CGImageRelease(croppedImageRef);
        if (filterType == GPUIMAGE_GRAYSCALE && !isPhotoBlackAndWhite) {
        GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:croppedImage];
        GPUImageColorInvertFilter *stillImageFilter = [[GPUImageColorInvertFilter alloc] init];
        [stillImageSource addTarget:stillImageFilter];
        [stillImageFilter useNextFrameForImageCapture];
        [stillImageSource processImage];
        UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentFramebuffer];
            [self.library saveImage:currentFilteredVideoFrame toAlbum:@"myCustomFolder" withCompletionBlock:^(NSError *error) {
                if (error!=nil) {
                    [self showErrorMessage:@"Unable to save image in photos album, please ensure this app must has permission access to photos album to save images."];
                    return ;
                }
                else {

                    NSString *message = @"Image saved";
                    UIAlertView *toast = [[UIAlertView alloc] initWithTitle:nil
                                                                    message:message
                                                                   delegate:nil
                                                          cancelButtonTitle:nil
                                                          otherButtonTitles:nil, nil];
                    [toast show];
                    int duration = 1;
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                        [toast dismissWithClickedButtonIndex:0 animated:YES];
                    });
                }

            }];
}

0 个答案:

没有答案