Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIImageWriteToSavedPhotosAlbum未将图像保存到相册_Iphone_Uiscrollview_Uiimageview_Ios6_Photo - Fatal编程技术网

Iphone UIImageWriteToSavedPhotosAlbum未将图像保存到相册

Iphone UIImageWriteToSavedPhotosAlbum未将图像保存到相册,iphone,uiscrollview,uiimageview,ios6,photo,Iphone,Uiscrollview,Uiimageview,Ios6,Photo,当用户长按图像时,我试图将图像从scrollview保存到相册中,操作表会显示“保存照片”按钮,当点击“保存”按钮时,它不会将图像保存到相册中 - (void)viewDidLoad { self.view.backgroundColor = [UIColor blackColor]; UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.

当用户长按图像时,我试图将图像从scrollview保存到相册中,操作表会显示“保存照片”按钮,当点击“保存”按钮时,它不会将图像保存到相册中

 - (void)viewDidLoad

{    self.view.backgroundColor = [UIColor blackColor];
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

    myButton.frame = CGRectMake(xOrigin, 10, 60, 35);

    //[myButton addGestureRecognizer:tap];

    [myButton.layer setMasksToBounds:YES];

    [myButton.layer setCornerRadius:10.0f];

    myButton.layer.borderWidth = 2;

    myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

    [myButton setTitle:@"Done" forState:UIControlStateNormal];

    myButton.backgroundColor = [UIColor clearColor];

    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    _imageView.tag = 128;
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);


    UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
                                                       initWithTarget:self
                                                       action:@selector(handleLongPress:)];

    //imageScrollView.userInteractionEnabled = YES;
    [imageScrollView addGestureRecognizer:gestureRecognizer];
    gestureRecognizer.delegate = self;
    [gestureRecognizer release];

    [imageScrollView addSubview:imageView];
    [imageScrollView addSubview:myButton];

    //[imageView release];

}
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

[self.view addSubview:imageScrollView];
[imageScrollView release];
 }



 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
    case 0:
    [_imageScrollView viewWithTag:128];
    UIImageWriteToSavedPhotosAlbum(_imageView.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);//When i add breakpoint at this statement in result it shows storage zero but alert view says success photo got saved in photo album

        break;

    default:
        break;
}
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
 {
if (error != NULL)
{

    alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                       message:@"Unable to save image to Photo Album."
                                      delegate:self cancelButtonTitle:@"Ok"
                             otherButtonTitles:nil];
     } else{
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    [alert show];
    [alert release];
   }
   }
-(void)viewDidLoad
{self.view.backgroundColor=[UIColor blackColor];
UIScrollView*imageScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
imageScrollView.PaginEnabled=是;
NSInteger numberOfViews=61;
对于(int i=0;i
请帮忙


谢谢

这可能是隐私设置的问题-人们一直在我的应用程序中遇到此问题,并且没有报告任何错误消息。理论上,试图保存照片时,应自动询问用户是否允许应用程序访问其照片,但在某些情况下,用户需要转到“设置”>“隐私”>“照片”,并确保允许您的应用程序。

您是否记录了任何内容?为什么有两个分号;;在UIImageWriteToSavedPhotosAlbum函数的末尾?是否收到任何错误消息?仅从您提供的代码很难判断。请在didFinishSavingWithError上设置一个断点,然后查看它的去向。让我们让您检查照片库中是否有照片。