Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- github
- darkmode
- 개발자
- Archive
- error
- Code
- appstore
- MacOS
- Swift
- FLUTTER
- JPA
- iOS16
- rxswift
- view
- SwiftUI
- IOS
- 한글
- Apple
- 이미지
- mac
- Xcode
- window
- Realm
- Notification
- UIButton
- Session
- geofencing
- 웹뷰
- Firebase
- Git
Archives
- Today
- Total
EEYatHo 앱 깎는 이야기
Swift ) Mail 앱으로 메일 보내기(MessageUI) - EEYatHo iOS 본문
반응형
Swift에서 Mail앱으로 메일을 전송할 수 있는 MessageUI라는 라이브러리를 지원합니다.
1. import해주시고,
import MessageUI
2. 액션시트나 Alert를 띄우는 것 마냥 간단하게 Modal 방식으로 present합니다.
if MFMailComposeViewController.canSendMail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["email@example.com", "email2@example.com"])
composeVC.setSubject("처음 보여줄 제목")
composeVC.setMessageBody("처음 보여줄 내용", isHTML: false)
// Present the view controller modally.
present(composeVC, animated: true)
} else {
// Mail앱을 사용할 수 없을 경우
...
}
3. 메일 전송이나 취소 등을 분기 처리하는 것을 delegate로 합니다.
extension MyViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
switch result {
case .sent:
// 메일 발송 성공 ( 인터넷이 안되는 경우도 sent처리되고, 인터넷이 연결되면 메일이 발송됨. )
case .saved:
// 메일 임시 저장
case .cancelled:
// 메일 작성 취소
case .failed:
// 메일 발송 실패 (오류 발생)
}
dismiss(animated: true)
}
}
'iOS, Swift' 카테고리의 다른 글
Swift ) Xcode Build Setting의 inherited - EEYatHo iOS (0) | 2021.04.26 |
---|---|
Swift ) XcodeGen - EEYatHo iOS (0) | 2021.04.20 |
Swift ) Archive 없이 Organizer창 열기 - EEYatHo iOS (0) | 2021.04.08 |
Swift ) IDFV - EEYatHo iOS (0) | 2021.04.08 |
Swift ) setNeedsLayout, layoutIfNeeded - EEYatHo iOS (0) | 2021.04.06 |
Comments