IOS images are stored in sandbox
-(Void) viewDidLoad {
[Super viewDidLoad];
// Initiate an attempt to attach an image
Imageview = [[UIImageView alloc] initWithFrame: CGRectMake (0, 50, self. view. frame. size. width, self. view. frame. size. height-100)];
[Self. view addSubview: imageview];
// Multithreading
Dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
NSURL * url = [NSURL URLWithString: kURL];
NSData * data = [[NSData alloc] initWithContentsOfURL: url];
Image = [[UIImage alloc] initWithData: data];
If (data! = Nil ){
Dispatch_async (dispatch_get_main_queue (), ^ {
Imageview. image = image;
NSFileManager * fileManager = [NSFileManager defaultManager];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSString * documentsDirectory = [paths objectAtIndex: 0];
NSString * myDirectory = [documentsDirectory stringByAppendingPathComponent: @ test];
NSString * filePath = [myDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @pic_%@.png, image];
NSLog (@ documentsDirectory % @, filePath );
[UIImagePNGRepresentation (image) writeToFile: filePath atomically: YES];
[FileManager createDirectoryAtPath: myDirectory withIntermediateDirectories: YES attributes: nil error: nil];
// NSData * data = [[NSData alloc] init];
// Data = [NSKeyedArchiver archivedDataWithRootObject: filePath];
// [Data writeToFile: myDirectory atomically: YES];
[Self thepictures];
});
}
});
}
// Retrieve the image from the sandbox
-(Void) thepictures
{
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSString * documentsDirectory = [paths objectAtIndex: 0];
NSLog (@ documentsDirectory % @, documentsDirectory );
NSFileManager * fileManage = [NSFileManager defaultManager];
NSString * myDirectory = [documentsDirectory stringByAppendingPathComponent: @ test];
NSArray * file = [fileManage subpathsOfDirectoryAtPath: myDirectory error: nil];
NSLog (@ % @, file );
NSArray * files = [fileManage subpathsAtPath: myDirectory];
NSLog (@%@, files );
}