撮影した画像をアプリケーションドキュメントディレクトリに保存したかったのですが、どういうわけか、カウンターは常に上がっていますが、ディレクトリ内に画像がありません。問題であると想定されるのは?
どうもありがとう!
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
[picker dismissModalViewControllerAnimated:YES];
self.imageViewRecipt.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//
// Getting the current counter value
//
NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
int imageCounter;
imageCounter = [[prefs objectForKey:@"imageCounter"]intValue];
//
// Obtaining saving path
//
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"image%i.png",imageCounter]];
//
// Extracting image from the picker and saving it
//
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"])
{
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *webData = UIImagePNGRepresentation(editedImage);
[webData writeToFile:imagePath atomically:YES];
//
// Saving the new counter into the plist
//
imageCounter++;
[prefs setInteger:imageCounter forKey:@"imageCounter"];
[prefs synchronize];
}
}