Skip to content

iOS에서 Google 로그인

GitHub

이 가이드에서 Google 로그인을 설정하는 방법을 배우고 Capgo Social Login for iOS를 사용하는 방법을 배웁니다. 이 가이드를 읽기 전에 이미 이 플러그인의 사용 방법을 읽었다고 가정합니다. 설정 가이드.

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. 선택 OAuth client ID

      인증서를 생성하는 메뉴에서
    5. Application type iOS 옵션을 선택하여 애플리케이션 유형을 선택하세요. iOS

      iOS 앱의 Bundle ID를 찾으세요.
    6. Xcode를 열어보세요.

      1. Xcode 프로젝트 탐색기에서

      2. App App

        Xcode에서 App을 선택하여
      3. 프로젝트 탭에서 App을 선택하세요. Targets -> App

        App을 선택하여 Targets 섹션을 확인하세요.
      4. Find your Bundle Identifier

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

        Google Console iOS 클라이언트 생성 양식의
    7. 선택적으로, App Store ID 에 붙여넣으세요. 만약 앱을 App Store에 출시한 적이 있다면. Team ID 모든 정보를 입력한 후,

    8. iOS 클라이언트 생성 양식 하단의 create

      클릭하세요.
    9. 클라이언트 ID 생성 확인 대화 상자에서 OK

      OK 버튼을 클릭하세요.
    10. iOS 클라이언트를 새로 생성한 것을 열어보세요.

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

      클라이언트 ID 정보가 나타나는데 클라이언트 ID와 클라이언트 ID를 뒤집어 복사할 수 있습니다.
  2. 애플리케이션의 Info.plist을 수정하세요.

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

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

      Info.plist 파일의 오른쪽 클릭 메뉴에 Open As Source Code 옵션이 표시됩니다.
    3. 파일의 하단 부분에서 Plist 파일 </dict> 태그

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

      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 이전 단계에서 복사한 값으로 설정

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

  3. 이 값을 수정하십시오. AppDelegate.swift

    1. Open the AppDelegate

      AppDelegate.swift 파일을 Xcode 프로젝트 탐색기에서 열기
    2. 추가 import GoogleSignIn 파일의 맨 위에 추가

      AppDelegate.swift에 GoogleSignIn import를 추가한 파일
    3. 찾기 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) 함수

      AppDelegate의 원래 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)
      }
      GoogleSignIn을 처리하는 수정된 openURL 함수
    5. 파일을 저장하기 Command + S

  4. Setup Google login in your JavaScript/TypeScript code

    1. Import SocialLogin and Capacitor

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

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

      // 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. Implement the login function. Create a button and run the following code on click

      For offline mode:

      const res = await SocialLogin.login({
      provider: 'google',
      options: {}
      })
      // handle the response - contains user data
      console.log(JSON.stringify(res))

      __CAPGO_KEEP_1__

      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. __CAPGO_KEEP_2__

    1. __CAPGO_KEEP_3__ cap sync

    2. __CAPGO_KEEP_4__

      __CAPGO_KEEP_5__

__CAPGO_KEEP_9__

__CAPGO_KEEP_10__

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

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

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 로그인 인증 및 계정 흐름을 계획하고 연결하려면 @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의 구현 세부 정보를 위해 두 가지 인증 방법 두 단계 인증 두 단계 인증의 구현 세부 정보를 위해