Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

drf1229

macrumors regular
Original poster
Jun 22, 2009
237
0
I am trying to find out whether or not a device is capable of using the phone feature by using sys/types.h and sysctl.h's HW_MACHINE identifier. My question is once I've imported sysctl and types can I just call HW_MACHINE to receive the current machine's class info? Is this accurate? When I do it this way, HW_MACHINE returns 1 in the simulator and 1 on my iPod touch. Is this the correct way of doing this? Any help would be appreciated, thanks!
 
Have you read this? You can enforce the requirement of the phone to launch the app, although it doesn't seem like you can check for it at runtime (easily).
 
Thanks for your responses!

To the first response:

Thank you for leading me to that guide, it seems pretty cool that you can do that. However, I want this app to be available to all systems, just so that if the phone feature is not available, show an alert saying "This device is not capable of..." if the person is using a device not capable of making calls


To the second response:

canOpenURL returns false in the simulator and my iPod touch. I haven't tested it on an iPhone since I do not have one. Could anyone reading this please tell me what the following code returns in an iPhone 3.0 or higher?

Code:
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString: @"tell://732-577-0440"]]){
		printf("Can");	
			
		}
		else {
			printf("Cannot");
		}
 
Ok, I got it working with the method in the first link, thanks a lot for your help! My final:
Code:
- (BOOL)deviceCanMakePhoneCalls
{
    BOOL canMakePhoneCalls;
    if ([UIApplication instancesRespondToSelector:@selector(canOpenURL:)]) {
        // OS 3.0+, so use canOpenURL
        UIApplication *app = [UIApplication sharedApplication];
        canMakePhoneCalls = ([app canOpenURL:[NSURL URLWithString:@"tel:+44-1234-567890"]]);
    } else {
        // OS 2.x, so check for iPhone
        UIDevice *device = [UIDevice currentDevice];
        canMakePhoneCalls = ([device.model isEqualToString:@"iPhone"]);
    }
    return canMakePhoneCalls;
}

- (IBAction)callCell {
	if([self deviceCanMakePhoneCalls]){	
	
		printf("Can");	
		//Call the person...
	}
	else {
		UIAlertView *alertTest = [[UIAlertView alloc]
								  initWithTitle:@"Unable to make call"
								  message:@"Sorry, this device is unable to make phone calls!"
								  delegate:self
								  cancelButtonTitle:@"Ok"
								  otherButtonTitles:nil];
		
		
		[alertTest show];
		[alertTest autorelease];
		printf("Cannot");
	}
	
	
}
 
I think OS 2.x- will attempt to open a "tel:" URL in safari (not quite sure why) so canOpenURL will return positive, even in a touch whereas 3.0+ will not even attempt to open the "tel:" URL if it is a touch (proven by apple's reply).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.