how do i launch the iphone sms text application in objective-c via the sms: url scheme?
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 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 bu开发者_运维知识库t sms: does not appear to work. Any idea what I am missing here?
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.
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...
You can also check if the device can invoke the SMS app with
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:stringURL]]
精彩评论