77//
88
99import UIKit
10+ import MessageUI
11+
1012import Common
1113
1214public final class SettingViewController : UIViewController {
13-
1415 private weak var coordinator : SettingCoordinatorInterface ?
1516 private var viewModel : SettingViewModel
1617
@@ -42,11 +43,9 @@ public final class SettingViewController: UIViewController {
4243 collectionView. delegate = self
4344 return collectionView
4445 } ( )
45-
4646}
4747
4848private extension SettingViewController {
49-
5049 func setUp( ) {
5150 view. backgroundColor = . white
5251 setUpNavigationBar ( )
@@ -74,6 +73,15 @@ private extension SettingViewController {
7473 coordinator? . finished ( )
7574 }
7675
76+ func didTapAskHelp( ) {
77+ if MFMailComposeViewController . canSendMail ( ) {
78+ let mailViewController = makeMailViewController ( )
79+ self . present ( mailViewController, animated: true , completion: nil )
80+ } else {
81+ self . showSendMailErrorAlert ( )
82+ }
83+ }
84+
7785 func setUpLayout( ) {
7886 view. addSubviews ( collectionView)
7987 NSLayoutConstraint . activate ( [
@@ -113,7 +121,7 @@ private extension SettingViewController {
113121 return section
114122 }
115123
116- private func setUpDataSource( ) {
124+ func setUpDataSource( ) {
117125 dataSource = UICollectionViewDiffableDataSource < SettingViewSection , Setting > (
118126 collectionView: collectionView,
119127 cellProvider: { collectionView, indexPath, item in
@@ -129,7 +137,7 @@ private extension SettingViewController {
129137 collectionView. dataSource = dataSource
130138 }
131139
132- private func applySnapshot( ) {
140+ func applySnapshot( ) {
133141 var snapshot = NSDiffableDataSourceSnapshot < SettingViewSection , Setting > ( )
134142 snapshot. appendSections ( [ . setting] )
135143 snapshot. appendItems ( Setting . settings ( ) )
@@ -138,7 +146,6 @@ private extension SettingViewController {
138146}
139147
140148extension SettingViewController : UICollectionViewDelegate {
141-
142149 public func collectionView( _ collectionView: UICollectionView , didSelectItemAt indexPath: IndexPath ) {
143150 guard let item = dataSource? . itemIdentifier ( for: indexPath) else {
144151 return
@@ -157,10 +164,37 @@ extension SettingViewController: UICollectionViewDelegate {
157164 coordinator? . showPrivacyRule ( )
158165
159166 case . askHelp:
160-
167+ didTapAskHelp ( )
161168
162169 default : break
163170 }
164171 }
172+ }
173+
174+ extension SettingViewController : MFMailComposeViewControllerDelegate {
175+ public func mailComposeController( _ controller: MFMailComposeViewController ,
176+ didFinishWith result: MFMailComposeResult ,
177+ error: Error ? ) {
178+ controller. dismiss ( animated: true )
179+ }
180+
181+ private func makeMailViewController( ) -> MFMailComposeViewController {
182+ let mailViewController = MFMailComposeViewController ( )
183+ mailViewController. mailComposeDelegate = self
184+ mailViewController
. setToRecipients ( [ " [email protected] " ] ) 185+ mailViewController. setSubject ( " 문의하기 " )
186+ mailViewController. setMessageBody ( " 서비스 이용에 어떤 문제가 있나요? " , isHTML: false )
187+
188+ return mailViewController
189+ }
165190
191+ private func showSendMailErrorAlert( ) {
192+ let alertController = UIAlertController ( title: " 메일 전송 실패 " ,
193+ message: " 아이폰 이메일 설정을 확인하고 다시 시도해주세요. " ,
194+ preferredStyle: . alert)
195+ let action = UIAlertAction ( title: " 확인 " , style: . default)
196+ alertController. addAction ( action)
197+
198+ present ( alertController, animated: true , completion: nil )
199+ }
166200}
0 commit comments