Whats going wrong?

Discussion in 'iOS Programming' started by arnieterm, Oct 9, 2008.

  1. arnieterm macrumors regular

    Joined:
    Aug 28, 2008
    #1
    I have a simple IPhone application that has two buttons
    Buttons1's title is set to a telephone number
    Button2 's title is set to an Email address
    On clicking Button1
    the below given code executes [inside button's click event]
    Code:
    UIButton	*btn=(UIButton*)sender;
    	NSString *strPhoneNumber=[@"tel://" stringByAppendingString: btn.currentTitle ];
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:strPhoneNumber]];	
    
    Similarly for Button2's case: the below given code executes
    Code:
    UIButton	*btn=(UIButton*)sender;
    	NSString *strPhoneNumber=[@"mailto://" stringByAppendingString: btn.currentTitle ];
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:strPhoneNumber]];
    
    I want to know a few things
    As soon as I click on either the Button1 or Button2 the application closes and nothing happens. I am running this application on IPhone and not in simulator.
    Is there anything wrong with the code?
    I am also not able to understand why my application closes
    Can anybody explain?
    Thanks
     
  2. mstoebe macrumors newbie

    Joined:
    Jul 24, 2008
    Location:
    Germany
    #2
    I don't have an exact solution for you but have you tried NSLogging your strings to make sure they are correct?

    Furthermore, your Application quits because you send the system a request to handle a URL. For "tel://"-URLs this is the Phone-Application, for "Mailto:"-URLs it's the MobileMail-App. So, what you should be seeing is that your App quits and the other app opens to handle your request. That's how it is supposed to work!

    What were you hoping for instead? What are you trying to accomplish?
     

Share This Page