Checking system information

Discussion in 'iOS Programming' started by drf1229, Dec 16, 2009.

  1. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #1
    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!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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).
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    What does canOpenURL: with a tel: URL return?
     
  4. drf1229 thread starter macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #4
    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");
    		}
     
  5. drf1229 thread starter macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #6
    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");
    	}
    	
    	
    }
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    What's wrong with using
    Code:
    [device.model isEqualToString:@"iPhone"]
    for both OS 2.x and 3.x?
     
  7. drf1229 thread starter macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #8
    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).
     
  8. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #9
    I Second!!
     

Share This Page