https://developers.google.com/identity/sign-in/ios/start-integrating?hl=ko
1. Cocoapods 설치
pod init
참고)
Xcode에서 코코아팟 설치시 최근 에러가 남
해결방법: 아래 Xcode 14.0-compatible -> Xcode 13.0-compatible로 바꿔준다.
pod 'GoogleSignIn'
pod install
2. OAuth 클라이언트ID 생성 (아래 링크에서 새 프로젝트 만든 뒤 또는 해당 프로젝트 선택 후)
https://console.developers.google.com/
3. info.plist source로 보기 누른 다음에 아래 코드 추가
(다른 블로그들에서 URL Types에 쓰라고 되어있어서 따라했다가 안됨. 아래 방법으로 성공)
<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
</array>
</dict>
</array>
단, Your ios client id, your dot reversed ios client id 는 본인 프로젝트에서 확인 가능 (커스텀해서 바꿀 것)
4. AppDelegate
import UIKit
import GoogleSignIn
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
if error != nil || user == nil {
// Show the app's signed-out state.
} else {
// Show the app's signed-in state.
}
}
return true
}
func application(
_ app: UIApplication,
open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
var handled: Bool
handled = GIDSignIn.sharedInstance.handle(url)
if handled {
return true
}
// Handle other custom URL types.
// If not handled by this app, return false.
return false
}
이후 서버에 ID 토큰 전송 관련:
https://developers.google.com/identity/sign-in/ios/backend-auth?hl=ko
참고 사이트
https://ksk9820.tistory.com/64
https://ios-development.tistory.com/144
참고 )
간혹 이전 글을 보면 AppDelegate에서
GIDSignInDelegate 를 이용하는 방법이 있는데,
이거는 예전 특정 버전으로 pod file 설치해주어야 함. pod 'GoogleSignIn', '~> 5.0.2'
참고) https://stackoverflow.com/questions/68395772/cannot-find-type-gidsignindelegate-in-scope
'iOS > iOS Swift ToyProject' 카테고리의 다른 글
swift Apple로 로그인 (0) | 2023.02.11 |
---|---|
TableView 안에 TextView 넣기 (0) | 2023.02.11 |
DynamicTableView 다른 크기의 셀 높이 지정 (0) | 2023.02.08 |
iOS swift swipe back gesture (0) | 2023.02.01 |
카카오톡 로그인 구현 (0) | 2023.01.31 |