views:

491

answers:

2

How can I exclude the call and sms feature from Ipod Touch but still retain it's functionality on the iPhone. The iPod Touch of course has no phone and sms is available via an optional app. Tech support kindly suggested I take a look at the system call "sysctlbyname" and the section on "CTL_HW" from the Apple provided iPhoneOS reference documentation. http://developer.apple.com/iphone/library/documentation/System/Conceptual/ManPages%5FiPhoneOS/man3/sysctlbyname.3.html

They said it is necessary to check the machine class and machine type to determine if the device is capable of supporting phone calling. Well I looked at it and it's Greek to me. On the other hand can this snippet from your forum:

[Bind(Exclude="ID, Name")]

be used to exclude assess to my in-app Contact Book feature on the iPod Touch? If so, I imagine it would be inserted into the RetrieveContactInfoViewController.m file, but in which section. (of course there are RetrieveContactInfoViewAppDelegate files available also). How can I exclude phone features from the iPod Touch?

+1  A: 

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)

Check out this page in the documentation.

It's for the UIDevice 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:

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");
}

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:

//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

That will even cache the result for you so it only does the string comparison once. Now you can do:

#import "UIDevice+ModelInfo.h"
if ([[UIDevice currentDevice] isiPhone]) {
  NSLog(@"Do something iPhoney");
} else {
  NSLog(@"I cannot do iPhoney things");
}

Merry Christmas.

Dave DeLong
Apple warns against making assumptions as to what device modal has what features. If there was for example an iPod Touch released with video camera then a hack like yours could exclude all those new devices for no good reason. Instead you should always check for a particular features.
PeyloW
@PeyloW touché.
Dave DeLong
Thanks a million to both Dave and PeyloW. I just want to block the telephony features from the iPod Touch, not to block the iPod out all together. I'll post the results. Digital D
Digital D
+4  A: 

A much easier and safer way to test for these capabilities on iPhone OS 3.0 is to query if the actual feature is supported, not what device you are. This can be easily done since both calling and sending text is registered URL schemas, so just ask if a URL for calling or sending text can be opened.

-(BOOL)canSendTextMessage;
{
  UIApplication* app = [UIApplication sharedApplication];
  return [app canOpenURL:[NSURL URLWithString:@"sms:12345"]];
}

-(BOOL)canMakePhoneCall;
{
  UIApplication* app = [UIApplication sharedApplication];
  return [app canOpenURL:[NSURL URLWithString:@"tel:12345"]];
}
PeyloW
Ok, after iPhone Provisioning Hell, I'm back. So we know that the iPod Touch has no phone. With respect to all parties, I think I will try Dave's method. I've created UIDevice+ModelInfo.m and h files and added them to my project....but am I to really use the last snippetverbatim? "Do something iphoney" and "I cannot do iphoney things"? #import "UIDevice+ModelInfo.h" if ([[UIDevice currentDevice] isiPhone]) { NSLog(@"Do something iPhoney"); } else { NSLog(@"I cannot do iPhoney things"); }Thanks again!digitalD}
Digital D
Please do **NOT** make assumptions on what features are available based ont he name of the device. What will happen if Apple releases an _iProduct_ next months? Will it have telephone, will it not? Either way your code will break if you check for iPhone explicitly, instead of correctly checking for features. It is almost worse than blocking websites based on the browser, instead of browser capabilities. I know we all hate being blocked because _"Internet Explorer required"_, and we all know the page works perfectly fine in Safari and Firefox. Do **NOT** make the same ugly assumptions!
PeyloW