How to launch SMS Message app

2020-07-10 07:34发布

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

标签: ios swift
3条回答
男人必须洒脱
2楼-- · 2020-07-10 07:59
// Swift 3
UIApplication.sharedApplication().openURL(NSURL(string: "sms:")!)

// Swift 4
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
查看更多
狗以群分
3楼-- · 2020-07-10 08:02

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)!)
查看更多
Lonely孤独者°
4楼-- · 2020-07-10 08:10

Swift 5:

let sms: String = "sms:+1234567890&body=Hello Abc How are You I am ios developer."
let strURL: String = sms.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
UIApplication.shared.open(URL.init(string: strURL)!, options: [:], completionHandler: nil)
查看更多
登录 后发表回答