<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhone Development Blog &#187; Device Information</title>
	<atom:link href="http://iPhoneIncubator.com/blog/category/device-information/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneIncubator.com/blog</link>
	<description>Tips and Tricks for iPhone, iPod, iPad and iOS Developers</description>
	<lastBuildDate>Tue, 03 Apr 2012 15:55:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Obtain Total and Available Disk Space on Your iPhone or iPod Touch</title>
		<link>http://iPhoneIncubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch</link>
		<comments>http://iPhoneIncubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch#comments</comments>
		<pubDate>Thu, 08 Oct 2009 19:12:53 +0000</pubDate>
		<dc:creator>Jess</dc:creator>
				<category><![CDATA[Device Information]]></category>
		<category><![CDATA[NSFileManager]]></category>
		<category><![CDATA[NSFileSystemSize]]></category>
		<category><![CDATA[statfs]]></category>

		<guid isPermaLink="false">http://iPhoneIncubator.com/blog/?p=290</guid>
		<description><![CDATA[A quick Internet search to find out how to get the disk space on a device showed a number of blog posts that proposed solutions similar to this:
#include &#60;sys/param.h&#62;
#include &#60;sys/mount.h&#62;

+(float)getTotalDiskSpaceInBytes {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	struct statfs tStats;
	statfs([[paths lastObject] cString], &#038;tStats);
	float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);

    return totalSpace;
}

This approach relies on the [...]<p>Post from <a href="http://iPhoneIncubator.com/blog">iPhone Development Blog</a> Copyright &copy; 2011 Nick Dalton - <a href="http://iPhoneIncubator.com/blog/portfolio">iPhone Developer</a><br/><br/><a href="http://iPhoneIncubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch">How To Obtain Total and Available Disk Space on Your iPhone or iPod Touch</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A quick Internet search to find out how to get the disk space on a device showed a number of blog posts that proposed solutions similar to this:</p>
<pre name="code" class="c">#include &lt;sys/param.h&gt;
#include &lt;sys/mount.h&gt;

+(float)getTotalDiskSpaceInBytes {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	struct statfs tStats;
	statfs([[paths lastObject] cString], &#038;tStats);
	float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);

    return totalSpace;
}
</pre>
<p>This approach relies on the handy Unix statfs() function that provides the required file system information. I coded it up and it worked on my 3.x devices.  Fine I thought, I&#8217;m off and running.  Then when testing on a 2.x device, it crashed.  The problem looks to be differences in the compiler settings between the two OS versions.  Rather than figure that out (I leave that as an exercise to the reader <img src='http://iPhoneIncubator.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ), I continued my search and came across what I consider the &#8220;correct&#8221; solution since it uses the iPhone SDK itself, as given below.</p>
<pre name="code" class="c">+(float)getTotalDiskSpaceInBytes {
	float totalSpace = 0.0f;
	NSError *error = nil;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &#038;error];

	if (dictionary) {
		NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
		totalSpace = [fileSystemSizeInBytes floatValue];
	} else {
		DLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
	}

    return totalSpace;
}
</pre>
<p>As stated in the documentation, these interfaces wrapper the statfs() function, so they ultimately do the same thing, but they have been a part of the SDK since version 2.0!  Testing verified my assumption and this approach works for me on my 2.x and 3.x devices and the numbers match what iTunes shows as well.</p>
<p>Post from <a href="http://iPhoneIncubator.com/blog">iPhone Development Blog</a> Copyright &copy; 2011 Nick Dalton - <a href="http://iPhoneIncubator.com/blog/portfolio">iPhone Developer</a><br/><br/><a href="http://iPhoneIncubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch">How To Obtain Total and Available Disk Space on Your iPhone or iPod Touch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneIncubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 259/259 objects using disk: basic

Served from: iphoneincubator.com @ 2012-05-17 02:35:32 -->
