IT/- 프로그래밍
iOS message app 열기
혁준7519
2020. 5. 1. 15:01
message app 열기
URL형태 : sms:전화번호&body=메시지
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import UIKit
class ViewController: UIViewController {
@IBOutlet var editMessage: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
// 메시지앱으로 이동
@IBAction func moveToMessageApp(_ sender: UIButton) {
var sms : String = "sms:01012341234"
// 메시지 내용이 있으면 전화번호 뒤에 &body=메시지를 붙이고 인코딩을 한다
if let msg = message , !msg.isEmpty {
sms = sms + "&body=" + msg
}
sms = sms.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! // 인코딩
UIApplication.shared.open( URL.init(string: sms)!, options: [:], completionHandler: nil )
}
}
|
결과
버튼 클릭시 메시지앱으로 이동하여 전화번호와 메시지를 설정한다

