Решение
Решение
Воспользуйтесь процедурой UIImageWriteToSavedPhotosAlbum:
— (void) imageWasSavedSuccessfully:(UIImage *)paramImage
didFinishSavingWithError:(NSError *)paramError
contextInfo:(void *)paramContextInfo{
if (paramError == nil){
NSLog(@"Image was saved successfully.");
} else {
NSLog(@"An error happened while saving the image.");
NSLog(@"Error = %@", paramError);
}
}
— (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"Picker returned successfully.");
NSLog(@"%@", info);
NSString *mediaType = [info objectForKey:
UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage]){
UIImage *theImage = nil;
if ([picker allowsEditing]){
theImage = [info objectForKey: UIImagePickerControllerEditedImage];
} else {
theImage = [info objectForKey: UIImagePickerControllerOriginalImage];
}
SEL selectorToCall = @selector(imageWasSavedSuccessfully:
didFinishSavingWithError: contextInfo:);
UIImageWriteToSavedPhotosAlbum(theImage,
self,
selectorToCall,
NULL);
}
[picker dismissModalViewControllerAnimated: YES];
}
— (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
NSLog(@"Picker was cancelled");
[picker dismissModalViewControllerAnimated: YES];
}
— (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear: animated];
static BOOL beenHereBefore = NO;
if (beenHereBefore){
/* Отображаем элемент для выбора даты только после того, как вызывается
метод viewDidAppear:, что происходит при каждом отображении вида
нашего контроллера вида */
return;
} else {
beenHereBefore = YES;
}
if ([self isCameraAvailable] &&
[self doesCameraSupportTakingPhotos]){
UIImagePickerController *controller =
[[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
NSString *requiredMediaType = (__bridge NSString *)kUTTypeImage;
controller.mediaTypes = [[NSArray alloc]
initWithObjects: requiredMediaType, nil];
controller.allowsEditing = YES;
controller.delegate = self;
[self.navigationController presentModalViewController: controller
animated: YES];
} else {
NSLog(@"Camera is not available.");
}
}
Методы isCameraAvailable и doesCameraSupportTakingPhotos, использованные в данном примере, подробно рассмотрены в разделе 13.1.
Данный текст является ознакомительным фрагментом.