티스토리 뷰
반응형
iOS 이메일 보내는 방법을 공유하겠습니다. iOS 이메일을 보내려면 MessageUI 가 필요합니다.
시작하기
■ 사용자가 이메일 기능을 사용 가능한지 체크합니다.
주의사항 iOS 이메일을 보내기 테스트 시 시뮬레이션에서는 동작하지 않으며 iOS 디바이스(iPhone)에서 이메일 테스트 해야합니다.
import Foundation
import UIKit
import MessageUI
class WelcomeViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
}
}
■ MFMailComposeviewController 로 메일 보내기
@IBAction func sendFeedbackButtonTapped(_ sender: Any) {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["exampleEmail@email.com"])
composeVC.setSubject("Message Subject")
composeVC.setMessageBody("Message content.", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
■ 이메일 취소 또는 보냈을 때 액션 처리
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {
// Check the result or perform other tasks.
// Dismiss tismiss(animated: true, completion: nil)
}
마무리
간단히 iOS 이메일 보내는 방법에 대해서 알아봤습니다.
여기서 주의할 점은 다음과 같습니다.
1) iOS 디바이스의 Email 로그인이 되어 있어야 합니다. 2) iOS 디바이스에서만 동작합니다. (시뮬레이터 동작 안함)
반응형
질문 또는 잘못된 정보는 댓글로 남겨주세요.
'프로그래밍 > iOS' 카테고리의 다른 글
[SWIFT] STOMP Client 맛보기 (2) | 2020.04.18 |
---|---|
iOS Shared Extention App Build Issue (0) | 2019.01.04 |
내부 배포용 앱 만들기(Enterprise) (0) | 2018.12.02 |
[SWIFT]클로저 (0) | 2018.10.24 |
iOS 인앱 평가 추가하기 (0) | 2018.08.22 |
댓글
최근에 올라온 글
최근에 달린 댓글
TAG
- flutter
- 알고리즘
- 고시문헬퍼
- Kotlin
- Android
- 탁구
- MCC
- 스코어헬퍼
- view
- missioon
- 임용고시
- 고시문
- 미션차이나센터
- DI
- IOS
- java
- missionchina
- 코틀린
- push
- 디자인패턴
- 점수판
- swift
- Android Studio
- RXjava
- 패턴
- IT
- 선교
- 안드로이드
- issue
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
글 보관함