I wrote a simple program to help me debug.
#import "UIImage+saveScreenShotOnDisk.h"
@implementation UIImage (saveScreenShotOnDisk)
-(void)saveScreenshot{
NSData * data = UIImagePNGRepresentation(self);
[data writeToFile:@"foo.png" atomically:YES];
}
@end
After it's executed, I want to know where foo.png
is located.
I went to
~Library/Application Support
and I can't find foo.png
. Where is it?
If I do
BOOL result = [data writeToFile:@"foo.png" atomically:YES];
the result will be NO
, which is kind of strange given that the simulator, unlike the iPhone, can write anywhere.
You need to direct the NSData object to the Path you want the data to be saved in:
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"foo.png"]];
[data writeToFile:databasePath atomically:YES];
This will save your file in your App's Folder on the device (or the simulator).
The default place, where the files are stored, is the folder your executable is stored.
See where your executable is stored via right clicking Products->YourExecutable :
Then open in finder.
Here pawel.plist
resource create via
NSArray *a = @[@"mybike", @"klapki", @"clapki", @"ah"];
[a writeToFile:@"pawel.plist" atomically:NO];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With