내용으로 건너뛰기

iOS에서 Google 로그인

소개

소개

In this guide, you will learn how to setup Google Login with Capgo Social Login for iOS. I assume that you have already read the 이 가이드에서, __CAPGO_KEEP_0__ Social Login for iOS와 Google 로그인을 설정하는 방법을 배울 것입니다. 이 가이드를 읽기 전에 이미 일반 설정 가이드를 읽었다고 가정합니다..

iOS에서 Google 로그인 사용하기

iOS에서 Google 로그인 사용하기

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

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

    1. 검색 바 클릭

      Google 콘솔 검색 바
    2. 검색하세요 credentials APIs 및 Services가 강조된 자격 증명 옵션을 보여주는 검색 결과 APIs and Services 자격 증명 옵션에 클릭하세요.

      Google 콘솔에서 자격 증명 생성 버튼 클릭
    3. 자격 증명 생성 메뉴에서 OAuth 클라이언트 ID 옵션을 선택하세요. create credentials

      __CAPGO_KEEP_0__
    4. __CAPGO_KEEP_0__ OAuth client ID

      __CAPGO_KEEP_0__
    5. 선택하세요. Application type __CAPGO_KEEP_0__ iOS

      iOS 옵션을 선택한 iOS 애플리케이션 타입 선택
    6. 버블 ID를 찾으세요.

      1. Xcode를 열어보세요.

      2. Xcode 프로젝트 탐색기에서 앱 대상에 두 번 클릭하세요. App

        Xcode 프로젝트 설정에서 Bundle Identifier 필드를 찾으세요.
      3. Xcode에서 Targets 섹션에 앱이 선택되어 있는지 확인하세요. Targets -> App

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

        __CAPGO_KEEP_0__
      5. __CAPGO_KEEP_0__ Bundle Identifier __CAPGO_KEEP_0__ Bundle ID

        __CAPGO_KEEP_1__의 Bundle ID 필드에 Google Console iOS 클라이언트 생성 양식에 입력하세요.
    7. __CAPGO_KEEP_2__를 선택적으로 추가하여 App Store ID __CAPGO_KEEP_3__에 앱을 App Store에 게시한 경우 클라이언트 ID에 입력하세요. Team ID 모든 세부 정보를 입력한 후

    8. iOS 클라이언트 생성 양식 하단의 Create 버튼을 클릭하세요. create

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

      새로 생성된 iOS 클라이언트를 열어보세요.
    10. 인증서 목록에 새로 생성된 iOS 클라이언트를 확인하세요.

      클라이언트 ID 생성 확인 대화 상자에서
    11. __CAPGO_KEEP_4__ 데이터를 복사하세요.

      __CAPGO_KEEP_0__
  2. __CAPGO_KEEP_0__

    1. __CAPGO_KEEP_0__ Info.plist __CAPGO_KEEP_0__

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

      Open As Source Code 옵션을 보여주는 오른쪽 클릭 메뉴
    3. Info.plist 파일의 Plist 태그 </dict> Info.plist 파일의

      태그
    4. Info.plist 파일의 </dict> 태그

      Info.plist 파일에 URL 스킴 code을 닫는 딕셔너리 태그 앞에 삽입
      <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 __CAPGO_KEEP_0__

      __CAPGO_KEEP_0__
    6. 파일을 Command + S

  3. 수정 AppDelegate.swift

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

      AppDelegate.swift 파일을 열어
    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. JavaScript/TypeScript code에서 Google 로그인 설정

    1. import SocialLogin 그리고 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

      클립보드 복사

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

    1. __CAPGO_KEEP_1__ cap sync

    2. __CAPGO_KEEP_2__

      __CAPGO_KEEP_3__

__CAPGO_KEEP_7__

__CAPGO_KEEP_8__

__CAPGO_KEEP_9__

__CAPGO_KEEP_10__

__CAPGO_KEEP_11__ @capacitor/개인정보 보호 화면Google 로그인 웹뷰와 함께 사용할 때, 개인정보 보호 화면이 로그인 화면을 중단합니다.

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