Reputation: 777
I'm trying to get specific phone information from the iOS device (for instance, "Apple iPhone 3G 16GB", "Apple iPhone 5S 64GB") in the code without prompting the user for it. So far, I know that you can use something like
[[UIDevice currentDevice] name]
to get if it's an iPhone, iPad or iPod Touch. However, is there a way to get more specific information directly through the iOS SDK, without using something like UIDeviceHardware (https://gist.github.com/Jaybles/1323251)? I've searched on SO for previous answers, and it doesn't seem like it's possible, but I just wanted to confirm my findings here. Thanks!
Upvotes: 0
Views: 131
Reputation: 50707
These are 2 separate informations.
[[UIDevice currentDevice] name] // e.g. Raymonds iPhone
What you want is the following:
[[UIDevice currentDevice] model] // e.g. iPhone, iPod touch, iPad, iOS Simulator
// or [[UIDevice currentDevice] localizedModel], e.g. Le iPod (j/k)
And for the device capacity, which there may be better examples, but this returns the space that is reported by the system:
- (NSString*)deviceCapacity
{
NSDictionary *attributesDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSTemporaryDirectory() error:NULL];
NSNumber *totalSize = [attributesDict objectForKey:NSFileSystemSize];
return [NSString stringWithFormat:@"%3.2f GB",[totalSize floatValue] /(1000*1000*1000)];
}
Note that the above example may return "14.37 GB" for a 16GB device (where 14.37 is the number the iOS reports, presumably the space after iOS is installed. So you can look at it as the user partition excluding the root partition.
So to put it all together, use this:
[NSString stringWithFormat:@"%@ %@", [[UIDevice currentDevice] model], [self deviceCapacity]];
Upvotes: 2