Skip to content

Commit

Permalink
[Chore] Health-Food-Me#12 - 햄버거바뷰 UI 관련파일 폴더 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Jul 12, 2022
1 parent c9f4a6c commit a4c9379
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 9 deletions.
10 changes: 1 addition & 9 deletions HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
3B0B255A2876CEBA00950539 /* Menu */ = {
isa = PBXGroup;
children = (
3B18D8AA287AB7B6009AF9E7 /* HamburgerBarScene */,
);
path = Menu;
sourceTree = "<group>";
};
3B18D8AA287AB7B6009AF9E7 /* HamburgerBarScene */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -507,6 +499,7 @@
EB6A44E22873BAAE00749582 /* Map */ = {
isa = PBXGroup;
children = (
3B18D8AA287AB7B6009AF9E7 /* HamburgerBarScene */,
EB6A44E32873BABE00749582 /* MainMapScene */,
);
path = Map;
Expand Down Expand Up @@ -837,7 +830,6 @@
EBF66A90287227F500DE0ED1 /* Presentation */ = {
isa = PBXGroup;
children = (
3B0B255A2876CEBA00950539 /* Menu */,
A9325272287D24CD001EDF50 /* Search */,
3BCC441A28745FA900661A12 /* Auth */,
EBF66A9F287227F500DE0ED1 /* Common */,
Expand Down
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>
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("애플아이디 로그인 실패")
}
}
}

0 comments on commit a4c9379

Please sign in to comment.