iOS: How do you find the creation date of a file?

This code actually returns the good creation date to me: NSFileManager* fm = [NSFileManager defaultManager]; NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil]; if (attrs != nil) { NSDate *date = (NSDate*)[attrs objectForKey: NSFileCreationDate]; NSLog(@”Date Created: %@”, [date description]); } else { NSLog(@”Not found”); } Are you creating the file inside the App? Maybe that’s where the … Read more

How to check if a file exists in Documents folder?

Swift 3: let documentsURL = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) … gives you a file URL of the documents directory. The following checks if there’s a file named foo.html: let fooURL = documentsURL.appendingPathComponent(“foo.html”) let fileExists = FileManager().fileExists(atPath: fooURL.path) Objective-C: NSString* documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString* foofile = [documentsPath stringByAppendingPathComponent:@”foo.html”]; BOOL … Read more

Create a folder inside documents folder in iOS apps

I do that the following way: NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@”/MyFolder”]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder

Storing images locally on an iOS device

The simplest way is to save it in the app’s Documents directory and save the path with NSUserDefaults like so: NSData *imageData = UIImagePNGRepresentation(newImage); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@”%@.png”,@”cached”]]; NSLog(@”pre writing to file”); if (![imageData writeToFile:imagePath atomically:NO]) { NSLog(@”Failed to cache image data to … Read more

NSFileManager.defaultManager().fileExistsAtPath returns false instead of true

(The code in this answer has been updated for Swift 3 and later.) Apparently your path variable is a NSURL (describing a file path). To get the path as a string, use the path property, not absoluteString: let exists = FileManager.default.fileExists(atPath: path.path) absoluteString returns the URL in a string format, including the file: scheme etc. … Read more

How to detect total available/free disk space on the iPhone/iPad device?

UPDATE: Since a lot of time has passed after this answer and new methods/APIs have been added, please check the updated answers below for Swift etc; Since I’ve not used them myself, I can’t vouch for them. Original answer: I found the following solution working for me: -(uint64_t)getFreeDiskspace { uint64_t totalSpace = 0; uint64_t totalFreeSpace … Read more