IOS images are stored in sandbox

Source: Internet
Author: User

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 );

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.