forked from Health-Food-Me/Health-Food-Me-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chore] Health-Food-Me#12 - 햄버거바뷰 UI 관련파일 폴더 이동
- Loading branch information
Showing
6 changed files
with
198 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
HealthFoodMe/HealthFoodMe/Presentation/Map/SocialLoginScene/VC/SocialLogin.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX"> | ||
<device id="retina6_1" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="System colors in document resources" minToolsVersion="11.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Social LoginVC--> | ||
<scene sceneID="s0d-6b-0kx"> | ||
<objects> | ||
<viewController storyboardIdentifier="SocialLoginVC" useStoryboardIdentifierAsRestorationIdentifier="YES" id="Y6W-OH-hqX" customClass="SocialLoginVC" customModule="HealthFoodMe" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc"> | ||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/> | ||
<color key="backgroundColor" systemColor="systemBackgroundColor"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="72" y="106"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<systemColor name="systemBackgroundColor"> | ||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
</systemColor> | ||
</resources> | ||
</document> |
164 changes: 164 additions & 0 deletions
164
HealthFoodMe/HealthFoodMe/Presentation/Map/SocialLoginScene/VC/SocialLoginVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// | ||
// SocialLoginVC.swift | ||
// HealthFoodMe | ||
// | ||
// Created by 강윤서 on 2022/07/05. | ||
// | ||
|
||
import UIKit | ||
|
||
import AuthenticationServices | ||
import KakaoSDKAuth | ||
import KakaoSDKCommon | ||
import KakaoSDKUser | ||
import SnapKit | ||
|
||
class SocialLoginVC: UIViewController { | ||
|
||
// MARK: - Properties | ||
private lazy var titleImageView = UIImageView() | ||
private lazy var subtitleImageView = UIImageView() | ||
private lazy var kakaoLoginButton = UIButton() | ||
private lazy var appleLoginButton = UIButton() | ||
|
||
// MARK: - View Life Cycle | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
setUI() | ||
setLayout() | ||
setAddTarget() | ||
} | ||
|
||
} | ||
|
||
// MARK: - extension | ||
extension SocialLoginVC { | ||
private func kakaoLogin() { | ||
if UserApi.isKakaoTalkLoginAvailable() { | ||
// 카카오톡 로그인. api 호출 결과를 클로저로 전달. | ||
UserApi.shared.loginWithKakaoTalk { (oauthToken, error) in | ||
if let _ = error { self.showKakaoLoginFailMessage() } else { | ||
if let accessToken = oauthToken?.accessToken { | ||
// 엑세스 토큰 받아와서 서버에게 넘겨주는 로직 작성 | ||
|
||
print("TOKEN", accessToken) | ||
self.postSocialLoginData(socialToken: accessToken, socialType: "KAKAO") | ||
} | ||
} | ||
} | ||
} else { // 웹으로 로그인해도 똑같이 처리되도록 | ||
UserApi.shared.loginWithKakaoAccount { (oauthToken, error) in | ||
if let _ = error { self.showKakaoLoginFailMessage() } else { | ||
if let accessToken = oauthToken?.accessToken { | ||
print("TOKEN", accessToken) | ||
self.postSocialLoginData(socialToken: accessToken, socialType: "KAKAO") | ||
} | ||
// 성공해서 성공 VC로 이동 | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func showKakaoLoginFailMessage() { | ||
self.makeAlert(title: I18N.Alert.error, message: I18N.Auth.kakaoLoginError, okAction: nil, completion: nil) | ||
} | ||
|
||
private func postSocialLoginData(socialToken: String, socialType: String) { | ||
|
||
} | ||
|
||
private func appleLogin() { | ||
let appleIDProvider = ASAuthorizationAppleIDProvider() | ||
let request = appleIDProvider.createRequest() | ||
request.requestedScopes = [.fullName, .email] | ||
|
||
let authorizationController = ASAuthorizationController(authorizationRequests: [request]) | ||
authorizationController.delegate = self | ||
authorizationController.presentationContextProvider = self | ||
authorizationController.performRequests() | ||
} | ||
|
||
private func setUI() { | ||
titleImageView.image = UIImage(named: "authTitle") | ||
subtitleImageView.image = UIImage(named: "authSubtitle") | ||
|
||
kakaoLoginButton.setTitle("카카오톡 아이디로 로그인", for: .normal) | ||
kakaoLoginButton.setTitleColor(.black, for: .normal) | ||
|
||
appleLoginButton.setTitle("애플 아이디로 로그인", for: .normal) | ||
appleLoginButton.backgroundColor = UIColor.black | ||
} | ||
|
||
private func setLayout() { | ||
view.addSubviews(titleImageView, subtitleImageView, kakaoLoginButton, appleLoginButton) | ||
titleImageView.snp.makeConstraints { make in | ||
make.top.equalToSuperview().inset(270) | ||
make.centerX.equalToSuperview() | ||
} | ||
|
||
subtitleImageView.snp.makeConstraints { make in | ||
make.top.equalTo(titleImageView.snp.bottom).offset(15) | ||
make.centerX.equalToSuperview() | ||
} | ||
|
||
kakaoLoginButton.snp.makeConstraints { make in | ||
make.top.equalTo(subtitleImageView.snp.bottom).offset(100) | ||
make.leading.trailing.equalToSuperview().inset(50) | ||
make.centerX.equalToSuperview() | ||
} | ||
|
||
appleLoginButton.snp.makeConstraints {make in | ||
make.top.equalTo(kakaoLoginButton.snp.bottom).offset(9) | ||
make.leading.trailing.equalToSuperview().inset(50) | ||
make.centerX.equalToSuperview() | ||
} | ||
} | ||
|
||
private func setAddTarget() { | ||
kakaoLoginButton.addTarget(self, action: #selector(doKakaoLogin), for: .touchUpInside) | ||
appleLoginButton.addTarget(self, action: #selector(doAppleLogin), for: .touchUpInside) | ||
} | ||
|
||
// MARK: - @objc Methods | ||
@objc func doKakaoLogin() { | ||
kakaoLogin() | ||
} | ||
|
||
@objc func doAppleLogin() { | ||
appleLogin() | ||
} | ||
} | ||
|
||
extension SocialLoginVC: ASAuthorizationControllerPresentationContextProviding { | ||
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { | ||
return self.view.window! | ||
} | ||
} | ||
|
||
extension SocialLoginVC: ASAuthorizationControllerDelegate { | ||
// Apple ID 연동 성공시 | ||
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { | ||
switch authorization.credential { | ||
// Apple ID | ||
case let appleIDCredential as ASAuthorizationAppleIDCredential : | ||
let userIdentifier = appleIDCredential.user | ||
let fullName = appleIDCredential.fullName | ||
let email = appleIDCredential.email | ||
|
||
print("User ID : \(userIdentifier)") | ||
print("User Email : \(email ?? "")") | ||
print("User Name : \((fullName?.givenName ?? "") + (fullName?.familyName ?? ""))") | ||
|
||
let identityToken = appleIDCredential.identityToken | ||
let tokenString = String(data: identityToken!, encoding: .utf8) | ||
|
||
if let token = tokenString { | ||
postSocialLoginData(socialToken: token, socialType: "APPLE") | ||
} | ||
default: | ||
// 실패 시 실패VC로 이동 | ||
print("애플아이디 로그인 실패") | ||
} | ||
} | ||
} |