Не могу написать (добавить UIImage) в фотоальбом - PullRequest
0 голосов
/ 28 июля 2010

У меня есть следующий код

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

NSLog(@"failed");
}

, который проверяет наличие ошибки и выдает время, когда я запускаю следующее

-(IBAction) addWallpaper{

UIImageWriteToSavedPhotosAlbum( [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]]
                               , self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
}

Как правильно сохранить UIImage в фотоальбом?

1 Ответ

1 голос
/ 28 июля 2010

Несмотря на имя

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
                               contextInfo:(void *)contextInfo

не указывает на ошибку.Вам нужно проверить error, переданное этой функции.

Что-то вроде:

-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error
                                  contextInfo:(void*)contextInfo
{
    UIAlertView *alert;
    if ( [error code] != 0 )
    {
            alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                       message:@"Things went wrong!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    } else {
            alert = [[UIAlertView alloc] initWithTitle:@"Great"
                       message:@"Image was saved!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    }
    [alert show];
    [alert release];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...