3

My app needs to know where iPad's mic is, and the only way I know is to see if it's running on iPad, or on iPad 2, and act accordingly.

So - how do I check the device model?

kolinko
  • 1,633
  • 1
  • 14
  • 31
  • 2
    I'm sorry I can't answer your question directly, but in general, if you want to test for the presence of a microphone, then test for the presence of a microphone. Indirection is not nice (you might not care, but if you check it's an iPad 2, what happens when iPad 3 comes out?). It's bad practice... – Dave May 13 '11 at 12:29
  • While this doesn't tell you the answer, have a read at this -> http://blog.mugunthkumar.com/coding/iphone-tutorial-better-way-to-check-capabilities-of-ios-devices/ – Dave May 13 '11 at 12:36
  • 1
    @Dave - thanks, but I don't want to test for the presence of microphone (iPad1 also has a mike), I need to test the *location* of microphone - iPad1 has a mike near headphones port, and iPad2 has a mike at the center. – kolinko May 13 '11 at 13:37
  • Aahh, I see! My bad - glad I could help below anyway! – Dave May 13 '11 at 13:40

2 Answers2

2

To do exactly this, you need:

if(![[UIDevice currentDevice].model isEqualToString:@"iPad2"])
{
UIAlertView *alertView = [UIAlertView alloc] initWithTitle:@"Error" 
message:@"Microphone not present" 
delegate:self 
cancelButtonTitle:@"Dismiss" 
otherButtonTitles: nil];
[alertView show];
[alertView release];
}

Taken from here

But as I said above, it'd be better to test for the presence of a Microphone than for the exact model. What if someone is using an iPad 1 with an external microphone?

EDIT: This is the correct method, apologies, Merlin.

Also covered in this stackoverflow question.

Dave

Community
  • 1
  • 1
Dave
  • 6,905
  • 2
  • 32
  • 35
  • 1
    thanks :) As I mentioned in the comment - I need the *location*, not the availability of microphone. I know that this is not a good practice, but I don't think there is an Api that will tell me where microphone is located :) – kolinko May 13 '11 at 13:38
  • Good to hear - apologies for misinterpreting the question! – Dave May 13 '11 at 13:41
  • 1
    ou. I just tested the code on the real device - iPad2 returns @"iPad", not @"iPad2" as a device model :( – kolinko May 16 '11 at 18:22
  • Merlin - apologies... This is the correct method - http://arstechnica.com/apple/guides/2009/03/iphone-dev-determining-your-platform.ars – Dave May 17 '11 at 07:49
  • 1
    Yeah, the initial method especially wouldn't work since the iPad 1 has a microphone, too. – Matthew Frederick May 17 '11 at 09:01
2

This SO answer provides a detailed method for using the sysctlbyname("hw.machine"... system.

Determine device (iPhone, iPod Touch) with iPhone SDK

Community
  • 1
  • 1
Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97