views:

987

answers:

3

I have a button in my obj-c application that I would like to launch the iphone text application when a button is pressed.

i've looked at the solution here http://stackoverflow.com/questions/2011139/how-to-use-iphone-custom-url-schemes and have attached an action to my button (via the 'touch up inside' event), but the text app doesn't launch when the button is pressed.

here is my code

(IBAction)sendMsgBtnPressed:(id)sender {

    NSLog(@"sendMsgBtnPressed");

    NSString *stringURL = @"sms:+14155551212";
    NSURL *url = [NSURL URLWithString:stringURL];
    [[UIApplication sharedApplication] openURL:url];

    [stringURL release];
}

i know this is being called because i can see the NSLog() output in my console. When I use a http:// scheme it works fine & launches Safari but sms: does not appear to work. Any idea what I am missing here?

+5  A: 

Try removing the leading plus sign before the numbers in your url. The plus sign is used for international numbers and you can safely replace it with two leading zeroes. Moreover, be sure to provide a string in which no space occurs between numbers: something like

NSString *stringURL = @"sms:00141555 51212"; will NOT work correctly.

One more thing. The statement

[stringURL release];

is not correct because stringURL has not being retained. You should remove it from your method.

unforgiven
thanks for the tips. You know what, I was testing in the iPhone simulator, and it apparently doesn't simulate the text application, but when i installed the app on my iphone it worked.
funkadelic
+2  A: 

Notice that the SMS application will be opened ONLY in iPhone device - not simulator and not iPod Touch.

The SMS application doesn't exist on simulator and iPod Touch...

Michael Kessler
+2  A: 

You can also check if the device can invoke the SMS app with

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:stringURL]]
samwize