I am currently saving a UIImage to the camera roll this way.
UIImageWriteToSavedPhotosAlbum(finalPicture.image, nil, nil, nil);
But what happens if the user denies us permission to access their photos... how can I tell that this has happened and display an error message?
To save the image to the camera roll I'm Using ALAssetsLibrary so in the method:
//Called after taking the photo with the camera or selected the image from the gallery
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *referenceURL;
if(Picker.sourceType==UIImagePickerControllerSourceTypeCamera){
UIImage* takenImage=info[UIImagePickerControllerOriginalImage];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[takenImage CGImage] orientation:(ALAssetOrientation)[takenImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
//NOT SAVED
//DISPLAY ERROR THE PICTURE CAN'T BE SAVED
} else {
//SAVED
}
}];
}
}else{
//Selected from gallery
}
Also remember that you have to check first if the camera is available.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//The camera is available
}else{
//No camera available
}