Reputation: 3661
I am making an iOS app that saves an image of given URL. I used the following code.
- (IBAction)save:(id)sender {
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoUrl]]];
NSLog(@"%f,%f",image.size.width,image.size.height);
// Let's save the file into Document folder.
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"saving jpg");
NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpg",docDir];
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
[data2 writeToFile:jpegFilePath atomically:YES];
NSLog(@"saving image done");
}
The image is saved successfully after calling this method. Since I use iPhone simulator, I can see the image is saved my local Library folder. However, when I open Photos (iPhone navie app) from the simulator, it doesn't detect the image I just saved. When I save an image from Safari and open Photos app, it detects the image correctly. But why can't it detect the image I saved thru my ios app? Any solutions?
Upvotes: 1
Views: 968
Reputation:
How come/why do you think or assume any image written to a random location should be known about by the Photos app? That's just nonsense. Use the UIImageWriteToSavedPhotosAlbum()
function instead.
Upvotes: 3