iOS에서 Google 로그인
설치 단계와 이 플러그인의 전체 마크다운 가이드와 함께 설정 프롬프트를 복사합니다.
이 가이드에서 Capgo Social Login for iOS와 Google Login을 설정하는 방법을 배울 것입니다. 이 가이드를 읽기 전에 이미 일반적인 설정 가이드를 읽었다고 가정합니다. 일반적인 설정 가이드.
iOS에서 Google 로그인을 사용하는 방법
iOS에서 Google 로그인을 사용하는 방법iOS에서 Google 로그인을 설정하는 방법에 대해 배울 것입니다.
-
Google 콘솔에서 iOS 클라이언트 ID를 생성하세요.
-
검색 바를 클릭하세요.
-
검색어를 입력하세요.
credentials스크린샷의 2번에 해당하는APIs and ServicesAPIs 및 Services가 강조된 자격 증명 옵션을 보여주는 검색 결과
-
Google Console
create credentials
-
선택
OAuth client ID
-
선택하세요.
Application type으로iOS
-
bundle ID를 찾으세요.
-
Xcode를 열어보세요.
-
__CAPGO_KEEP_0__
App
-
__CAPGO_KEEP_1__
Targets -> App
-
__CAPGO_KEEP_2__
Bundle Identifier
-
Google 콘솔로 돌아가서
Bundle Identifier를Bundle ID
-
-
Optionally, 앱 스토어에 게시한 앱에 대한
App Store ID또는Team ID를 클라이언트 ID에 추가하세요. -
모든 세부 정보를 입력한 후
create
-
Create 버튼을 클릭하세요.
OK
-
OK 버튼 클릭하세요. 클라이언트 ID가 생성되었습니다.
-
__CAPGO_KEEP_0__을 복사하세요.
-
-
iOS 클라이언트가 새로 생성된 자격 증명 목록에 추가되었습니다.
-
Xcode를 열고 프로젝트 탐색기에서
Info.plist파일
-
이 파일을 오른쪽 클릭하고 code으로 열기
-
파일의 하단 부분에서
Plist태그</dict>Info.plist 파일의
-
닫는 태그 바로 앞에 다음 코드를 삽입하세요
</dict>Info.plist에 URL schemes __CAPGO_KEEP_0__을 삽입한 닫는 태그
<key>CFBundleURLTypes</key><array><dict><key>CFBundleURLSchemes</key><array><string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string></array></dict></array> -
변경
YOUR_DOT_REVERSED_IOS_CLIENT_ID이전 단계에서 복사한 값을 입력하세요
-
파일을 저장하세요
Command + S
-
-
수정
AppDelegate.swift-
AppDelegate를 열기
-
삽입
import GoogleSignIn파일의 맨 위에
-
찾아보기
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:])함수
-
함수를 다음처럼 수정하세요
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {// Called when the app was launched with a url. Feel free to add additional processing here,// but if you want the App API to support tracking app url opens, make sure to keep this callvar handled: Boolhandled = GIDSignIn.sharedInstance.handle(url)if handled {return true}return ApplicationDelegateProxy.shared.application(app, open: url, options: options)}
-
파일을
Command + S
-
-
Setup Google login in your JavaScript/TypeScript code
-
Import
SocialLogin및Capacitorimport { SocialLogin } from '@capgo/capacitor-social-login';import { Capacitor } from '@capacitor/core'; -
초기화 메서드를 호출하세요 (이 메서드는 한 번만 호출해야 함)
기본 설정 (온라인 모드 - 대부분의 앱에 권장):
// onMounted is Vue specificonMounted(() => {SocialLogin.initialize({google: {iOSClientId: '673324426943-redacted.apps.googleusercontent.com',mode: 'online' // Default mode}})})추가 클라이언트 ID를 사용하는 고급 설정:
onMounted(() => {SocialLogin.initialize({google: {webClientId: 'YOUR_WEB_CLIENT_ID', // Optional: for web platform supportiOSClientId: 'YOUR_IOS_CLIENT_ID', // Required: from step 1iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Optional: same as webClientId, needed for some advanced featuresmode: 'online' // 'online' or 'offline'}})}) -
Implement the login function. Create a button and run the following code on click
For online mode:
const res = await SocialLogin.login({provider: 'google',options: {}})// handle the response - contains user dataconsole.log(JSON.stringify(res))오프라인 모드:
const res = await SocialLogin.login({provider: 'google',options: {forceRefreshToken: true // Recommended for offline mode}})// res contains serverAuthCode, not user data// Send serverAuthCode to your backend to get user information// Do not call SocialLogin.refresh() in offline modeconsole.log('Server auth code:', res.result.serverAuthCode)
-
-
애플리케이션 테스트
-
앱 빌드 및 실행
cap sync -
모든 것을 올바르게 수행했는지 확인했으면, Google 로그인 흐름이 올바르게 작동하는 것을 볼 수 있어야 합니다.
-
알려진 문제
알려진 문제Privace Screen 플러그인 불일치
개인 정보 보호 화면 플러그인 불일치Google 로그인 플러그인은 @capacitor/privacy-screen개인 정보 보호 화면이 로그인 웹뷰를 중단할 수 있습니다.
해결 방법: Call await PrivacyScreen.disable(); 로그인 함수를 호출하기 전에:
import { PrivacyScreen } from '@capacitor/privacy-screen';import { SocialLogin } from '@capgo/capacitor-social-login';
await PrivacyScreen.disable();await SocialLogin.login({ provider: 'google', options: {}});