Skip to content

Commit

Permalink
소셜미디어 LOGIN 연동
Browse files Browse the repository at this point in the history
- Google login 연동
- apple login 연동
  - apple login Developer 계정 미등록으로 로직구현 미완
  - 추후 로직 구현 업데이트 예정
  • Loading branch information
donghun-ha committed Dec 21, 2024
1 parent e730f19 commit 686eb56
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 70 deletions.
27 changes: 21 additions & 6 deletions DateSpot/DateSpot/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,37 @@
//

import UIKit
import FirebaseCore
import FirebaseCore // import Firebase
import GoogleSignIn // import Google

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Firebase 초기화 코드 추가
func application(
_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Firebase 초기화
FirebaseApp.configure()
print("Connect Success")
print("Firebase 연결 성공")

// GoogleSignIn 초기화
if let clientID = FirebaseApp.app()?.options.clientID {
GIDSignIn.sharedInstance.configuration = GIDConfiguration(clientID: clientID)
print("Google ClientID 초기화 성공: \(clientID)")
}else{
print("Google ClientID 초기화 실패")
}
return true
}


// MARK: - Google Login
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}

// MARK: UISceneSession Lifecycle
// MARK: - UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
Expand Down
21 changes: 21 additions & 0 deletions DateSpot/DateSpot/Assets.xcassets/google.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "google.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 54 additions & 13 deletions DateSpot/DateSpot/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="h3O-yK-pl4">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="jT2-b8-gbP">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
Expand All @@ -22,7 +22,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="lla-Qj-cMG" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-2205" y="-470"/>
<point key="canvasLocation" x="-1092.3664122137404" y="-471.12676056338029"/>
</scene>
<!--Map View Controller-->
<scene sceneID="q05-3x-bZQ">
Expand All @@ -39,12 +39,12 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="E4J-Fb-HpJ" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1199" y="-470"/>
<point key="canvasLocation" x="-225" y="-471"/>
</scene>
<!--User View Controller-->
<!--Bookmark View Controller-->
<scene sceneID="uF1-2Y-qKW">
<objects>
<viewController id="dDk-TX-crI" customClass="UserViewController" customModule="DateSpot" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="dDk-TX-crI" customClass="BookmarkViewController" customModule="DateSpot" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Z2U-q6-WKx">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand All @@ -56,7 +56,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DPu-ho-5sD" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-201" y="-470"/>
<point key="canvasLocation" x="700" y="-471"/>
</scene>
<!--User View Controller-->
<scene sceneID="RVW-uW-1Tg">
Expand All @@ -71,17 +71,21 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Login"/>
<connections>
<action selector="btnLogin:" destination="JpY-bj-ttb" eventType="touchUpInside" id="hHJ-Oa-8bz"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="8D9-Bd-XWA"/>
<color key="backgroundColor" systemColor="systemBrownColor"/>
</view>
<tabBarItem key="tabBarItem" title="" image="person" catalog="system" id="0sl-gL-Fas"/>
<tabBarItem key="tabBarItem" title="" image="person" catalog="system" id="npr-0r-asF"/>
<navigationItem key="navigationItem" id="mrf-TU-B9Q"/>
<simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rah-Ut-lfr" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="859" y="-470"/>
<point key="canvasLocation" x="1636" y="-471"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="OSD-Oc-ukb">
Expand All @@ -93,22 +97,59 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="PZS-9a-ij4" kind="relationship" relationship="viewControllers" id="ZZ7-dH-NTj"/>
<segue destination="31I-UB-cSi" kind="relationship" relationship="viewControllers" id="Vxf-tc-wGq"/>
<segue destination="dDk-TX-crI" kind="relationship" relationship="viewControllers" id="Ob2-Pl-x7r"/>
<segue destination="JpY-bj-ttb" kind="relationship" relationship="viewControllers" id="0y4-Te-OlI"/>
<segue destination="PZS-9a-ij4" kind="relationship" relationship="viewControllers" destinationCreationSelector="sgHome" id="ZZ7-dH-NTj"/>
<segue destination="31I-UB-cSi" kind="relationship" relationship="viewControllers" destinationCreationSelector="sgMap" id="Vxf-tc-wGq"/>
<segue destination="dDk-TX-crI" kind="relationship" relationship="viewControllers" destinationCreationSelector="sgBookmark" id="Ob2-Pl-x7r"/>
<segue destination="JpY-bj-ttb" kind="relationship" relationship="viewControllers" destinationCreationSelector="sgUser" id="jbx-t2-E2u"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3Ux-RH-AZv" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-706" y="-1204"/>
<point key="canvasLocation" x="220.61068702290075" y="-1204.2253521126761"/>
</scene>
<!--Login View Controller-->
<scene sceneID="aeh-Nl-q9l">
<objects>
<viewController id="KWR-QK-1CC" customClass="LoginViewController" customModule="DateSpot" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="mQ1-v5-xg7">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="31x-OO-lBD"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="Xbf-6I-NlE"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sSv-bf-Han" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1481.679389312977" y="-1204.2253521126761"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="gGT-JS-OYN">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="jT2-b8-gbP" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="XRu-Lg-Mdo">
<rect key="frame" x="0.0" y="59" width="393" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="KWR-QK-1CC" kind="relationship" relationship="rootViewController" destinationCreationSelector="sgLogin" id="jZU-69-fNe"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="LdT-fW-gJu" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-2408.3969465648852" y="-1204.2253521126761"/>
</scene>
</scenes>
<resources>
<image name="bookmark" catalog="system" width="110" height="128"/>
<image name="house" catalog="system" width="128" height="104"/>
<image name="map" catalog="system" width="128" height="112"/>
<image name="person" catalog="system" width="128" height="121"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBlueColor">
<color red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
Expand Down
99 changes: 99 additions & 0 deletions DateSpot/DateSpot/Controller/LoginViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// LoginViewController.swift
// DateSpot
//
// Created by 하동훈 on 21/12/2024.
//

import UIKit
import AuthenticationServices // Apple Login
import GoogleSignIn // Google Login

class LoginViewController: UIViewController {

// MARK: - Properties
// Google 로그인 버튼
let googleButton = UIButton()
// Apple 로그인 버튼
let authorizationAppleIDButton = ASAuthorizationAppleIDButton()

// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
configureUI() // UI 설정
}

// MARK: - UI Configuration
/// 화면의 UI 요소들을 구성하는 메서드
private func configureUI() {
view.backgroundColor = .white // 배경 색상 설정
setupGoogleLoginButton() // Google 버튼 추가
setupAppleLoginButton() // Apple 버튼 추가
}

// MARK: - Google
/// Google 로그인 버튼 구성 및 레이아웃 설정
private func setupGoogleLoginButton() {

// 이미지 추가
let googleLogo = UIImage(named: "google") // 로컬 이미지 사용
googleButton.setImage(googleLogo, for: .normal)
googleButton.imageView?.contentMode = .scaleAspectFit

// Google 버튼 Auto Layout 활성화
googleButton.translatesAutoresizingMaskIntoConstraints = false
googleButton.addTarget(self, action: #selector(handleGoogleSignIn), for: .touchUpInside) // Google 로그인 동작 추가
view.addSubview(googleButton)

// Google 버튼 제약 조건 설정
NSLayoutConstraint.activate([
googleButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), // 화면 중앙에 정렬
googleButton.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -40), // 화면 중심보다 위로 40pt
googleButton.widthAnchor.constraint(equalToConstant: 200), // 버튼 너비 200pt
googleButton.heightAnchor.constraint(equalToConstant: 50) // 버튼 높이 50pt
])
}

// MARK: - Apple
/// Apple 로그인 버튼 구성 및 레이아웃 설정
private func setupAppleLoginButton() {
// Apple 버튼 Auto Layout 활성화
authorizationAppleIDButton.translatesAutoresizingMaskIntoConstraints = false
authorizationAppleIDButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButton(_:)), for: .touchUpInside) // 버튼 동작 설정
view.addSubview(authorizationAppleIDButton)

// Apple 버튼 제약 조건 설정
NSLayoutConstraint.activate([
authorizationAppleIDButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), // 화면 중앙에 정렬
authorizationAppleIDButton.topAnchor.constraint(equalTo: googleButton.bottomAnchor, constant: 20), // Google 버튼 아래로 20pt
authorizationAppleIDButton.widthAnchor.constraint(equalToConstant: 200), // 버튼 너비 200pt
authorizationAppleIDButton.heightAnchor.constraint(equalToConstant: 50) // 버튼 높이 50pt
])
}

// MARK: - Selectors
/// Apple 로그인 버튼 동작 처리
@objc private func handleAuthorizationAppleIDButton(_ sender: ASAuthorizationAppleIDButton) {
print("Apple Login Button Tapped")
// 여기에 Apple 로그인 처리 로직 추가
}

@objc private func handleGoogleSignIn() {
// Google 로그인 실행
GIDSignIn.sharedInstance.signIn(
withPresenting: self
) { user, error in
if let error = error {
print("Google 로그인 실패: \(error.localizedDescription)")
return
}

// 로그인 성공 시 사용자 정보 출력
guard let user = user else { return }
print("Google 로그인 성공!")
print("사용자 이름: \(user.user)")

// TODO: 로그인 성공 후 동작 추가 (예: 다음 화면으로 이동)
// self.performSegue(withIdentifier: "sgHome", sender: self)
}
}} // LoginViewController
70 changes: 38 additions & 32 deletions DateSpot/DateSpot/Controller/UserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,51 @@ import UIKit
import AuthenticationServices

class UserViewController: UIViewController {

private let signInButton = ASAuthorizationAppleIDButton()
// MARK: - Properties
let authorizationAppleIDButton = ASAuthorizationAppleIDButton()

override func viewDidLoad() {
super.viewDidLoad()
signInButton.addTarget(self, action: #selector(didTapSignIn), for: .touchUpInside)
// Do any additional setup after loading the view.
configureUI()
setupAppleLoginButton()
}
// MARK: - Apple UI
private func configureUI() {
// setAdditionalPropertyAttributes()
// setConstraints()
setupAppleLoginButton()
}

@objc func didTapSignIn() {
print("Start sign in")

let provider = ASAuthorizationAppleIDProvider()
let requset = provider.createRequest()
// 사용자에게 제공받을 정보를 선택 (이름 및 이메일) -- 아래 이미지 참고
requset.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [requset])
// 로그인 정보 관련 대리자 설정
controller.delegate = self
// 인증창을 보여주기 위해 대리자 설정
controller.presentationContextProvider = self
// 요청
controller.performRequests()
func setupAppleLoginButton() {
// ASAuthorizationAppleIDButton을 사용해 애플 로그인 버튼 생성
let appleLoginButton = ASAuthorizationAppleIDButton(type: .signIn, style: .whiteOutline)
appleLoginButton.translatesAutoresizingMaskIntoConstraints = false
appleLoginButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButton(_:)), for: .touchUpInside)

// 버튼을 화면에 추가
self.view.addSubview(appleLoginButton)

// 오토레이아웃 설정
NSLayoutConstraint.activate([
appleLoginButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
appleLoginButton.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
appleLoginButton.heightAnchor.constraint(equalToConstant: 50),
appleLoginButton.widthAnchor.constraint(equalToConstant: 300)
])
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
@IBAction func btnLogin(_ sender: Any) {
print("Login Button")
// 로그인 화면으로 이동
let loginViewController = LoginViewController()
self.navigationController?.pushViewController(loginViewController, animated: true)
}
*/


}

// MARK: - Selectors
@objc private func handleAuthorizationAppleIDButton(_ sender: ASAuthorizationAppleIDButton) {
print(#function)
}


}// UserViewController

4 changes: 4 additions & 0 deletions DateSpot/DateSpot/GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>511873124565-116bkdde5os1qpk1jb3ggaf6n0kskagb.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.511873124565-116bkdde5os1qpk1jb3ggaf6n0kskagb</string>
<key>API_KEY</key>
<string>AIzaSyC1QNVeVWBk7s-h1CVLokPebHdNyYoBf00</string>
<key>GCM_SENDER_ID</key>
Expand Down
Loading

0 comments on commit 686eb56

Please sign in to comment.