내용으로 건너뛰기

iOS에서 Google 로그인

GitHub 저장소

이 가이드에서 Google 로그인과 Capgo iOS용 Social Login을 설정하는 방법을 배웁니다. 이미 이 가이드의 내용을 읽으셨다고 가정합니다. 설정 가이드.

iOS에서 Google 로그인을 사용하는 방법

iOS에서 Google 로그인을 사용하는 방법

iOS에서 Google 로그인을 설정하는 방법에 대해 배울 것입니다.

  1. iOS 클라이언트 ID를 Google 콘솔에 생성하세요.

    1. 검색 바를 클릭하세요.

      Google 콘솔 검색 바
    2. 검색하세요. credentials 그리고 APIs and Services 스크린샷의 2번에 표시된 옵션을 클릭하세요.

      APIs 및 Services가 강조된 자격 증명 옵션을 표시하는 검색 결과
    3. 자격 증명 옵션을 클릭하세요. create credentials

      Google Console에서 인증서를 생성하는 메뉴에서 OAuth 클라이언트 ID 옵션을 선택하세요.
    4. Select OAuth client ID

      인증서를 생성하는 메뉴에서 OAuth 클라이언트 ID 옵션을 선택하세요.
    5. Select the Application type iOS iOS

      iOS 옵션을 선택하여 애플리케이션 유형을 선택하세요.
    6. Bundle ID를 찾으세요.

      1. Xcode를 열어보세요.

      2. App target을 App

        App target을 Xcode 프로젝트 탐색기에서 두 번 클릭하세요.
      3. Capgo가 App target을 선택한 상태에서 Targets 섹션에 있습니다. Targets -> App

        Targets 섹션에서 App을 선택한 상태로 있습니다.
      4. Find your Bundle Identifier

        Xcode 프로젝트 설정에서 Bundle Identifier 필드를 찾으세요.
      5. Google Console로 돌아가서 앱의 Bundle Identifier Bundle ID 필드에 붙여넣으세요. Bundle ID

        iOS 클라이언트 생성 폼의 Bundle ID 필드에
    7. App Store에 앱을 출시한 경우, 앱의 App Store ID 또는 Team ID App Store에 앱을 출시한 경우, 앱의

    8. 클라이언트 ID에 붙여넣으세요. create

      모든 정보를 입력한 후, iOS 클라이언트 생성 폼 하단의
    9. iOS 클라이언트 생성 폼 하단의 OK

      클라이언트 ID 생성 확인 대화 상자에서 OK 버튼을 클릭하세요.
    10. iOS 클라이언트를 새로 생성한 것을 열어주세요.

      새로 생성한 iOS 클라이언트가 인증 정보 목록에 나타납니다.
    11. 다음 데이터를 복사하세요.

      클라이언트 ID 정보가 나타나는데 클라이언트 ID와 클라이언트 ID를 뒤집은 것을 복사하세요.
  2. __CAPGO_KEEP_0__

    1. Xcode에서 프로젝트 탐색기에서 Info.plist 파일

      Xcode 프로젝트 탐색기에서 Info.plist 파일을 찾으세요
    2. 이 파일을 오른쪽 클릭하고 소스 코드로 열기 code

      소스 코드로 열기 Code 옵션을 보여주는 오른쪽 클릭 메뉴
    3. 파일의 하단 부분에서 Plist 파일의 하단 부분에서 </dict> 태그

      Info.plist 파일의 닫는 태그
    4. 닫는 태그 바로 앞에 다음 코드 조각을 삽입하세요. </dict> __CAPGO_KEEP_0__

      code URL 스키마를 Info.plist에 삽입하기 전에 닫는 괄호 태그에 삽입합니다.
      <key>CFBundleURLTypes</key>
      <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
      </array>
      </dict>
      </array>
    5. 이전 단계에서 복사한 값을 YOUR_DOT_REVERSED_IOS_CLIENT_ID 으로 변경

      URL 스키마에 실제로 역순된 클라이언트 ID를 삽입한 Info.plist
    6. 파일을 저장하세요. Command + S

  3. 이 값을 수정하세요. AppDelegate.swift

    1. Xcode 프로젝트 탐색기에서 AppDelegate.swift 파일을 열어 주세요.

      AppDelegate.swift 파일에서 GoogleSignIn import를 추가한 파일을 열어 주세요.
    2. 위에 import GoogleSignIn AppDelegate.swift 파일에 GoogleSignIn import를 추가한 파일을 열어 주세요.

      GoogleSignIn import를 추가한 AppDelegate.swift 파일을 찾으세요.
    3. 함수 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) AppDelegate.swift 파일의 원래 openURL 함수를 찾으세요.

      함수를 다음처럼 수정하세요.
    4. 클립보드에 복사하세요.

      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 call
      var handled: Bool
      handled = GIDSignIn.sharedInstance.handle(url)
      if handled {
      return true
      }
      return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
      }
      파일을 저장하세요.
    5. AppDelegate.swift 파일에 GoogleSignIn import를 추가한 파일을 열어 주세요. Command + S

  4. code에 Google 로그인을 설정하세요.

    1. Import SocialLoginCapacitor

      import { SocialLogin } from '@capgo/capacitor-social-login';
      import { Capacitor } from '@capacitor/core';
    2. initialize 메소드를 호출하세요 (이 메소드는 한 번만 호출해야 합니다).

      기본 설정 (온라인 모드 - 대부분의 앱에 권장):

      // onMounted is Vue specific
      onMounted(() => {
      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 support
      iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required: from step 1
      iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Optional: same as webClientId, needed for some advanced features
      mode: 'online' // 'online' or 'offline'
      }
      })
      })
    3. 로그인 함수를 구현하세요. 버튼을 만들고 클릭 시 다음 code을 실행하세요.

      온라인 모드:

      const res = await SocialLogin.login({
      provider: 'google',
      options: {}
      })
      // handle the response - contains user data
      console.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 mode
      console.log('Server auth code:', res.result.serverAuthCode)
  5. 애플리케이션 테스트

    1. 앱을 빌드하고 실행하세요 cap sync

    2. 모든 것을 올바르게 완료했다면, Google 로그인 흐름이 올바르게 작동하는 것을 볼 수 있어야 합니다.

      iOS에서 Google 로그인 흐름의 데모

알려진 문제

알려진 문제

개인 정보 보호 화면 플러그인 불일치

개인 정보 보호 화면 플러그인 불일치 섹션

Google 로그인 플러그인은 @capacitor/privacy-screen개인 정보 보호 화면이 Google 로그인 웹뷰를 중단할 수 있습니다.

해결 방법: 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: {}
});

iOS에서 Google 로그인으로 계속하기

iOS에서 Google 로그인으로 계속하기 섹션

iOS에서 Google 로그인을 사용하는 경우 iOS에서 Google 로그인 인증 및 계정 흐름을 계획하고 연결하려면 @capgo/capacitor-social-login을 사용하여 @capgo/capacitor-social-login의 네이티브 기능을 사용하여 @capgo/capacitor-social-login @capgo/capacitor-social-login의 구현 세부 정보를 위해 @capgo/capacitor-passkey @capgo/capacitor-passkey의 구현 세부 정보를 위해 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric의 구현 세부 정보를 위해, iOS에서 두 단계 인증 두 단계 인증의 구현 세부 정보를 위해.