Tuesday, November 2, 2010

condition of allowed run the application in the both iPhone sdk etc.

Ref.: AvailabilityInternel.h class

//#if __IPHONE_3_2 >= __IPHONE_OS_VERSION_MAX_ALLOWED
//#endif

Monday, October 18, 2010

NSFileManager to save an image to or load/remove an image from documents directory

Reference link :
http://www.friendlydeveloper.com/2010/02/using-nsfilemanager-to-save-an-image-to-or-loadremove-an-image-from-documents-directory-coding/
special thanks for "friendlydeveloper"

NSFileManager offers a convenient way to write images to and load them from the documents directory.
If you’re frequently doing that in your project, I suggest to wrap up NSFileManager support in three simple methods:
01//saving an image
02 
03- (void)saveImage:(UIImage*)image:(NSString*)imageName {
04 
05NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
06 
07NSFileManager *fileManager = [NSFileManager defaultManager];
08 
09NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
10 
11NSString *documentsDirectory = [paths objectAtIndex:0];
12 
13NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
14 
15[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
16 
17NSLog(@"image saved");
18 
19}
20 
21//removing an image
22 
23- (void)removeImage:(NSString*)fileName {
24 
25NSFileManager *fileManager = [NSFileManager defaultManager];
26 
27NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
28 
29NSString *documentsDirectory = [paths objectAtIndex:0];
30 
31NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", fileName]];
32 
33[fileManager removeItemAtPath: fullPath error:NULL];
34 
35NSLog(@"image removed");
36 
37}
38 
39//loading an image
40 
41- (UIImage*)loadImage:(NSString*)imageName {
42 
43NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
44 
45NSString *documentsDirectory = [paths objectAtIndex:0];
46 
47NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
48 
49return [UIImage imageWithContentsOfFile:fullPath];
50 
51}
Now, you can easily save an image like:
1[self saveImage: myUIImage: @"myUIImageName"];
or load it like:
1myUIImage = [self loadImage: @"myUIImageName"];
or remove it like:
1[self removeImage: @"myUIImageName"];