Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand your question correctly, you want to limit features of your own app based on whether the app is running on an iPod touch versus an iPhone? If that's the case... (if not, you need to rephrase your question)</p> <p><a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/doc/uid/TP40006902-CH3-SW1" rel="nofollow noreferrer">Check out this page in the documentation</a>.</p> <p>It's for the <code>UIDevice</code> class, which allows you to access basic information regarding the device on which the app is running. The method linked to above is the "model" property of the UIDevice. It can be very useful. For example:</p> <pre><code>if ([[[UIDevice currentDevice] model] rangeOfString:@"iPhone"].location != NSNotFound) { NSLog(@"I am running on an iPhone (or in the simulator)"); } else { NSLog(@"I am running on an iPod touch"); } </code></pre> <p>To use that in a large number of places could be tedious. This is where it would be helpful to make a category on UIDevice, like so:</p> <pre><code>//UIDevice+ModelInfo.h @interface UIDevice (ModelInfo) - (BOOL) isiPhone; @end //UIDevice+ModelInfo.m @implementation UIDevice (ModelInfo) - (BOOL) isiPhone { static BOOL isiPhone; static BOOL modelTypeInitialized; if (modelTypeInitialized == NO) { modelTypeInitialized = YES; isiPhone = ([[self model] rangeOfString:@"iPhone"] != NSNotFound); } return isiPhone; } @end </code></pre> <p>That will even cache the result for you so it only does the string comparison once. Now you can do:</p> <pre><code>#import "UIDevice+ModelInfo.h" if ([[UIDevice currentDevice] isiPhone]) { NSLog(@"Do something iPhoney"); } else { NSLog(@"I cannot do iPhoney things"); } </code></pre> <p>Merry Christmas.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload