put iOS How many images are cached locally? Now , what are some of the ways students learn about iOS development notes in the Wheat Academy?
<code> cache the pictures locally, in a lot of scenes will be used, if only to store text information, then build a plist files, or databases, can be very convenient to solve problems, but if you save the picture to the sandbox is not so convenient. Here are two ways to save a picture to a sandbox.
</code>
I. Convert the image into a base64 string into a database or plist file, and then remove it when you use it.
<codeclass= "Hljs" objectivec= "" >// Gets the sandbox path,
NSString *path_sandox = Nshomedirectory ();
// Create a storage plist path to the file
NSString *newpath = [Path_sandoxstringbyappendingpathcomponent:@/documents/pic.plist];
Nsmutablearray *arr = [[Nsmutablearray alloc]init];
// convert the picture to Base64 the string
NSString *image64 = [Selfencodetobase64string:image];
[Arr addobject:image64];
// Write plist file
if ([arr WriteToFile:newPathatomically:YES]) {
NSLog (@ write succeeded );
};
</code>
And then save it and use it to convert the stored string into a picture.
<codeclass= "Hljs" perl= "" >nsdata *_decodedimagedata = [[NSData alloc]initwithbase64encoding:image64];
UIImage *_decodedimage =[uiimage imagewithdata:_decodedimagedata];</code>
Two. Save the picture directly to the sandbox, and then store the path, and then take the path to the image and get the picture by the path.
<code class= "Hljs" objectivec= "" >// get the picture .
UIImage *image = [UIImage imagenamed: @flower. png]; Nsstring*path_sandox = Nshomedirectory ();
// Set the storage path for a picture
NSString *imagepath = [Path_sandoxstringbyappendingstring:@/documents/flower.png];
// Save the picture directly to the specified path (you should also ImagePath the path to the image save it, you can use it directly next time .
[Uiimagepngrepresentation (image) writetofile:imagepathatomically:yes];</code>
Next time use the address of the picture to get the picture directly.
Also attach the code to get the sandbox directory
Sandbox file directory get code:
Home Directory
<code class= "Hljs" fix= "" >nsstring*homedirectory = Nshomedirectory ();</code>
Document Directory
<code class= "Hljs" objectivec= "" >nsarray*paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *path = [Paths objectatindex:0];</code>
Cache Directory
<code class= "Hljs" objectivec= "" >nsarray*paths = Nssearchpathfordirectoriesindomains (NSCachesDirectory, Nsuserdomainmask, YES);
NSString *path = [Paths objectatindex:0]; </code>
Libaray Directory
<code class= "Hljs" objectivec= "" >nsarray*paths = Nssearchpathfordirectoriesindomains (NSLibraryDirectory, Nsuserdomainmask, YES);
NSString *path = [Paths objectatindex:0];</code>
More Wheat Academy iOS Development Tutorials and notes at:http://www.maiziedu.com/course/ios/
Wheat Academy iOS notes: Several ways iOS caches pictures locally