diff --git a/KkuMulKum/Application/SceneDelegate.swift b/KkuMulKum/Application/SceneDelegate.swift index 8c666266..1b3c8a38 100644 --- a/KkuMulKum/Application/SceneDelegate.swift +++ b/KkuMulKum/Application/SceneDelegate.swift @@ -31,7 +31,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { DispatchQueue.main.async { if success { print("Auto login successful, showing main screen") - self?.showLoginScreen() + self?.showMainScreen() } else { print("Auto login failed, showing login screen") self?.showLoginScreen() diff --git a/KkuMulKum/Source/MyPage/View/MyPageEtcSettingView.swift b/KkuMulKum/Source/MyPage/View/MyPageEtcSettingView.swift index c2868500..5db11575 100644 --- a/KkuMulKum/Source/MyPage/View/MyPageEtcSettingView.swift +++ b/KkuMulKum/Source/MyPage/View/MyPageEtcSettingView.swift @@ -11,6 +11,9 @@ import SnapKit import Then class MyPageEtcSettingView: BaseView { + + let kakaoShareTapped = ObservablePattern(nil) + let stackView = UIStackView(axis: .vertical).then { $0.spacing = 24 $0.distribution = .fillEqually @@ -74,7 +77,7 @@ class MyPageEtcSettingView: BaseView { switch index { case 0: - print("버전정보 탭됨") + kakaoShareTapped.value = () case 1: print("이용약관 탭됨") case 2: diff --git a/KkuMulKum/Source/MyPage/View/MyPageView.swift b/KkuMulKum/Source/MyPage/View/MyPageView.swift index c3bea878..8df2e02c 100644 --- a/KkuMulKum/Source/MyPage/View/MyPageView.swift +++ b/KkuMulKum/Source/MyPage/View/MyPageView.swift @@ -14,7 +14,7 @@ class MyPageView: BaseView { private let topBackgroundView = UIView(backgroundColor: .white) private let contentView = MyPageContentView() private let alarmView = MyPageAlarmSettingView() - private let etcSettingView = MyPageEtcSettingView() + let etcSettingView = MyPageEtcSettingView() override func setupView() { backgroundColor = .green1 diff --git a/KkuMulKum/Source/MyPage/ViewController/MyPageViewController.swift b/KkuMulKum/Source/MyPage/ViewController/MyPageViewController.swift index 0dcf5fda..3d2a3c17 100644 --- a/KkuMulKum/Source/MyPage/ViewController/MyPageViewController.swift +++ b/KkuMulKum/Source/MyPage/ViewController/MyPageViewController.swift @@ -6,6 +6,9 @@ // import UIKit +import KakaoSDKCommon +import KakaoSDKTemplate +import KakaoSDKShare class MyPageViewController: BaseViewController { private let rootView = MyPageView() @@ -14,8 +17,46 @@ class MyPageViewController: BaseViewController { view = rootView } + override func setupView() { - view.backgroundColor = .green1 - setupNavigationBarTitle(with: "마이페이지") - } + view.backgroundColor = .green1 + setupNavigationBarTitle(with: "마이페이지") + + bindViewModel() + } + + private func bindViewModel() { + rootView.etcSettingView.kakaoShareTapped.bind { [weak self] _ in + self?.shareKakaoTemplate() + } + } + + private func shareKakaoTemplate() { + let templateId = 110759 + + if ShareApi.isKakaoTalkSharingAvailable() { + ShareApi.shared.shareCustom(templateId: Int64(templateId)) { [weak self] (sharingResult, error) in + if let error = error { + print("카카오톡 공유 실패: \(error)") + self?.showAlert(title: "공유 실패", message: "카카오톡 공유에 실패했습니다.") + } + else { + print("카카오톡 공유 성공") + if let sharingResult = sharingResult { + UIApplication.shared.open(sharingResult.url, options: [:], completionHandler: nil) + } + } + } + } + else { + print("카카오톡 미설치") + self.showAlert(title: "알림", message: "카카오톡이 설치되어 있지 않습니다.") + } + } + + private func showAlert(title: String, message: String) { + let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: nil)) + present(alertController, animated: true, completion: nil) + } }