Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch SMS Message app

Tags:

ios

swift

I want to open SMS Message App to copy some text from friends. I am not creating SMS.

How to launch iphone SMS Message app using Swift code? I come across this code below for launching Mail app but not working.


[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:"]];

I changed it to and the same not working

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:"]];

appreciate your help. TIA

like image 277
MilkBottle Avatar asked Jul 02 '15 09:07

MilkBottle


People also ask

How do I open SMS app?

From the Home screen, tap the Apps icon (in the QuickTap bar) > the Apps tab (if necessary) > Tools folder > Messaging .

Why is my SMS app not working?

Fix problems sending or receiving messagesMake sure you have the most updated version of Messages. If you have a SIM card, ensure that it is inserted properly. If you're on Fi, sign in to the Project Fi app. Verify that Messages is set as your default texting app.


3 Answers

Swift 5:

let sms = "sms:+1234567890&body=Hello Abc How are You I am ios developer."
let strURL = sms.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
UIApplication.shared.open(URL(string: strURL)!, options: [:], completionHandler: nil)
like image 51
oskarko Avatar answered Oct 06 '22 01:10

oskarko


I'm not sure why you want to explicitly use SMS app and I'm not sure if it's possible. On the other hand iOS by default offers MFMessageComposeViewController for sending SMS from iOS app.

Check this Swift example for more details.

Edit: I've found this wiki page which may contain answer for your question. Be aware I haven't tested it.

let number = "sms:+12345678901"
UIApplication.sharedApplication().openURL(NSURL(string: number)!)
like image 20
Josip B. Avatar answered Oct 05 '22 23:10

Josip B.


// Swift 3
UIApplication.sharedApplication().openURL(NSURL(string: "sms:")!)

// Swift 4
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
like image 30
Reming Hsu Avatar answered Oct 06 '22 00:10

Reming Hsu