NS Data
//********** STORE NSDATA **********
NSString *FilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/users.xml"];
[FileData writeToFile:FilePath atomically:YES]; //Write it overwriting any previous file (atomically writes to a temporary location before copying to permanent - good protection in case app should crash)
//********** GET NSDATA **********
NSString *FilePath;
NSData *FileData;
NSString *FilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/users.xml"];
FileData = [NSData dataWithContentsOfFile:FilePath];
if (!FileData)
NSLog(@"Error - File not found");
Camera Images
//********** STORE IMAGE **********
- (void)imageStore:(UIImage *)image forKey:(NSString *)key
{
//----- WRITE IMAGE TO FILE -----
NSString *imagePath = pathInDocumentDirectory(key); //Get file path (using FileHelpers function)
NSData *d = UIImageJPEGRepresentation(image, 0.5); //Turn into JPEG data (compression quality is float value of 0=lowest to 1=highest)
[d writeToFile:imagePath atomically:YES]; //Write it overwriting any previous file (atomically writes to a temporary location before copying to permanent - good protection in case app should crash)
}
//********** GET IMAGE **********
- (UIImage *)imageRead:(NSString *)key
{
UIImage *storedImage = [UIImage imageWithContentsOfFile:pathInDocumentDirectory(key)]; //Get file path (using FileHelpers function)
if (!storedImage)
NSLog(@"Error - Image not found: %@", pathInDocumentDirectory(key));
return storedImage;
}
//********** DELETE IMAGE **********
- (void)imageDelete:(NSString *)key
{
NSString *path = pathInDocumentDirectory(key); //Get file path (using FileHelpers function)
[[NSFileManager defaultManager] removeItemAtPath:path
error:nil];
}