Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2010, 07:08 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
nexirius is on a distinguished road
Default Find out device type?

Is it difficult to find out my device? How can I properly do it
with the example below?

I could use for my app something like

Code:
if(device==ipad) {
     do this
} else if(device==iphone4) {
     do that
} else {
     do that
}
nexirius is offline   Reply With Quote
Old 07-16-2010, 07:12 AM   #2 (permalink)
57Digital Ltd, Mobile Dev
iPhone Dev SDK Supporter
 
iPhoneConnection's Avatar
 
Join Date: Apr 2010
Location: Sheffield
Posts: 144
iPhoneConnection is on a distinguished road
Default

You can use [UIDevice currentDevice].model to get the current device model. UIDevice class reference will give you the possible constant strings which you can compare to (although you might want to check for iPad too).

Remember, you should always compare strings with the isEqualToString: rather than using the comparison operator.


Quote:
Originally Posted by nexirius View Post
Is it difficult to find out my device? How can I properly do it
with the example below?

I could use for my app something like

Code:
if(device==ipad) {
     do this
} else if(device==iphone4) {
     do that
} else {
     do that
}

Last edited by iPhoneConnection; 07-16-2010 at 07:16 AM.
iPhoneConnection is offline   Reply With Quote
Old 07-16-2010, 07:17 AM   #3 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Johanovski is on a distinguished road
Default

Hi nexirius!

There's an easy way to know some device's properties such as it's name, it's OS and some more things:
Code:
[[UIDevice currentDevice] model]; //for example this will return a string that represents the device's model
Check out what [UIDevice currentDevice] can return you (for example, if operating system is 3.2 then you're sure device is an iPad), I'm not sure if it will do what you're expecting, but if not I've seen some days ago a class someone has developed that can be used to check exactly which device model is (I'm sorry, I don't have it hehe), I think it's called "DeviceDetection.h" or something like this...

Hope it helped!
Johanovski is offline   Reply With Quote
Old 07-16-2010, 08:11 AM   #4 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

UI_USER_INTERFACE_IDIOM()

Will return something like UIUserInterfaceIdiomPad or UIUserInterfaceIdiomPhone. The nice thing about this, it works on all firmwares. The #define that will just return UIUserInterfaceIdiomPhone if UIDevice is too old to support the actual method.

Max
mxweas is offline   Reply With Quote
Old 07-16-2010, 09:00 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Bostonia
Posts: 53
evan1466 is on a distinguished road
Default UI_USER_INTERFACE_IDIOM

I used this.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

}
evan1466 is offline   Reply With Quote
Old 07-16-2010, 09:54 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 11
geniusprograms is on a distinguished road
Default

Quote:
Originally Posted by nexirius View Post
Is it difficult to find out my device? How can I properly do it
with the example below?

I could use for my app something like

Code:
if(device==ipad) {
     do this
} else if(device==iphone4) {
     do that
} else {
     do that
}
Try this:
Code:
- (NSString *)deviceName {
    return [[UIDevice currentDevice] name];
}
returns "iPhone 3G" if on a iPhone 3G
or "iPhone Simulator" if on the iPhone simulator etc...

Here's my implementation:
Code:
#define iPhone4 @"iPhone 4"
#define iPhone3G @"iPhone 3G"
#define iPhone @"iPhone"
#define iPad @"iPad"
#define iPhone3GS @"iPhone 3G S"

- (NSString *)deviceName {
    return [[UIDevice currentDevice] name];
}

- (void)viewWillAppear:(BOOL)animated {
   if ([[self deviceName] isEqualToString:iPhone4]) {
       NSLog(@"You're an iPhone 4");
   } else if ([[self deviceName] isEqualToString:iPad]) {
       NSLog(@"You're an iPad");
   }
}
__________________

Coding is the easy bit. The hard bit is figuring out what code to write

My app (Documentation): Here
geniusprograms is offline   Reply With Quote
Old 07-16-2010, 10:41 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
nexirius is on a distinguished road
Default

Sounds great! My main goal is to be able to see if I'm dealing with an iPad
or iPhone. But of course it's useful if you can even find out which version
you have (for example iPhone 4 and the rest) because you have different
screen resolutions!

Thanks a lot for your input. I will try some stuff of it.
nexirius is offline   Reply With Quote
Old 10-21-2010, 03:46 PM   #8 (permalink)
Hardcore Flagger
 
Join Date: Oct 2010
Posts: 12
inGGames is on a distinguished road
Exclamation

Actually
Code:
[[UIDevice currentDevice] name]
will return the name of the phone the user sets when setting it up, so it is not reliable for this sort of testing!
inGGames is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
15 members and 321 guests
akphyo, alexP, appservice, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, mariano_donati, ohmniac, Paul Slocum, PavelSea, Rudy, SLIC, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0