{"id":3090,"date":"2012-02-14T02:06:07","date_gmt":"2012-02-13T21:06:07","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=3090"},"modified":"2025-04-27T19:02:12","modified_gmt":"2025-04-27T19:02:12","slug":"how-to-find-available-disk-space-of-ios-device","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/how-to-find-available-disk-space-of-ios-device\/","title":{"rendered":"How To Find Available Disk Space of iOS Device?"},"content":{"rendered":"<p>Hello, iOS fellows;<br \/>\nHope life is as bright as the retina display of <a href=\"http:\/\/www.apple.com\/iphone\/\" target=\"_blank\" rel=\"noopener\">iPhone 4S<\/a>\u00a0 (:<\/p>\n<p>Well, its a Valentine&#8217;s night and I&#8217;m writing this blog post at mid night, thinking that may be someone get some benefit with these few lines and saved his\/her time to googling here and there; Ahh what a priorities of an engineer? (:<br \/>\n<!--more--><\/p>\n<p>I was working on an iOS application where I had needed to determine the available disk space on user&#8217;s device, to warn the user about storage.<\/p>\n<p>Here is the code I used that finds out the space in bytes:<\/p>\n<p>[code]<\/p>\n<p>+(void)calculateSpaceOnDisk {<br \/>\n   NSError *error = nil;<br \/>\n   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);<br \/>\n   NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &amp;amp;error];<br \/>\n   if (dictionary) {<br \/>\n      float freeSpace  = [[dictionary objectForKey: NSFileSystemFreeSize] floatValue];<br \/>\n      float totalSpace = [[dictionary objectForKey: NSFileSystemSize] floatValue];<br \/>\n   } else {<br \/>\n      NSLog(@&amp;quot;Error Obtaining File System Info: Domain = %@, Code = %@&amp;quot;, [error domain], [error code]);<br \/>\n   }<br \/>\n}\/\/end calculateSpaceOnDisk:<\/p>\n<p>[\/code]<\/p>\n<p>The highlighted lines are soul of this post.<\/p>\n<p>Note that I&#8217;m storing all of my application&#8217;s data in<strong> <em>Library\/Cache<\/em><\/strong> directory, not in <em><strong>\/Document<\/strong>;<\/em> Not sure right now how it may affect the above piece of code;<\/p>\n<p>Stay bright;<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/s03.flagcounter.com\/count\/ehB\/bg_FFFFFF\/txt_000000\/border_FFFFFF\/columns_6\/maxflags_248\/viewers_0\/labels_1\/pageviews_1\/flags_0\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, iOS fellows; Hope life is as bright as the retina display of iPhone 4S\u00a0 (: Well, its a Valentine&#8217;s night and I&#8217;m writing this blog post at mid night, thinking that may be someone get some benefit with these few lines and saved his\/her time to googling here and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[177,386,554,814,815,817],"class_list":["post-3090","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","tag-available-disk-space","tag-find-free-space-in-xcode","tag-iphone","tag-nsfilesystemfreesize","tag-nsfilesystemsize","tag-nssearchpathfordirectoriesindomains"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=3090"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3090\/revisions"}],"predecessor-version":[{"id":5162,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3090\/revisions\/5162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/5161"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=3090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=3090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=3090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}