iOS上のGoogleログイン
インストールステップとこのプラグインのフルマークダウンガイドまでのすべてのステップが含まれたセットアップ用の質問をコピーしてください。
このガイドでは、Capgo Social Login for iOSとGoogleログインを設定する方法を学びます。 既読の「一般的なセットアップガイド」を読んだことを前提としています。 一般的なセットアップガイド.
Googleログインの使用方法
Section titled “Googleログインの使用方法”このセクションでは、GoogleログインをiOSで設定する方法を学びます。
-
GoogleコンソールでiOSクライアントIDを作成する
-
検索バーをクリックする
-
検索する
credentialsクリックするAPIs and Services1 (スクリーンショットの2番目)
-
Google Console の
create credentials
-
クレデンシャル作成メニューの
OAuth client ID
-
を選択します。
Application typeiOS オプションが強調表示されたアプリケーションタイプの選択iOS
-
Xcode を開きます。
-
Xcode プロジェクトナビゲータで
-
ターゲットをダブルクリックします。
App
-
Capgoの設定を確認してください
Targets -> App
-
Capgoで
Bundle Identifier
-
Google Consoleに戻り、Capgoで生成した
Bundle IdentifierGoogle ConsoleのiOSクライアント作成フォームのBundle IDフィールドに貼り付けますBundle ID
-
-
またはApp Storeにアプリを公開した場合は、クライアントIDに追加してください
App Store IDApp Storeにアプリを公開した場合は、クライアントIDに追加してくださいTeam IDすべての詳細を入力したら、iOSクライアント作成フォームの下部にある -
iOSクライアント作成フォームの下部にある
create
-
Click
OK
-
Open the newly created iOS client
-
Copy the following data
-
-
Modify your app’s Info.plist
-
Xcodeを開いて、プロジェクトナビゲータで
Info.plistファイル
-
Right click this file and open it as source code
-
下部の
Plistファイルの</dict>タグ
-
次に閉じるタグの直前に以下のフラグメントを挿入してください。
</dict>タグ
<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 GoogleSignInAppDelegate.swiftファイルの先頭にGoogleSignIn importを追加
-
検索
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)}
-
Save the file with
Command + S
-
-
Setup Google login in your JavaScript/TypeScript code
-
ファイルを保存してください
SocialLoginJavaScript/TypeScriptでGoogleログインを設定するCapacitorimport { SocialLogin } from '@capgo/capacitor-social-login';import { Capacitor } from '@capacitor/core'; -
Call the initialize method (this should be called only once)
クリップボードにコピー
// onMounted is Vue specificonMounted(() => {SocialLogin.initialize({google: {iOSClientId: '673324426943-redacted.apps.googleusercontent.com',mode: 'online' // Default mode}})})基本設定(オンラインモード - 大多数のアプリ向けに推奨):
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
オンラインモードの場合:
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 ログインフローが正常に動作するはずです
-
問題点
「問題点」セクションプライバシー画面プラグインの不互換性
「プライバシー画面プラグインの不互換性」セクション@__CAPGO_KEEP_0__/privacy-screen @capacitor/privacy-screen対策:
呼び出す ログイン関数を呼び出す前に 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: {}});@__CAPGO_KEEP_0__
iOS上のGoogleログインから続けるあなたが iOS上のGoogleログイン 認証とアカウントフローの計画に使用している場合、 Capacitorの@capgo/capacitor-social-login Capacitorの@capgo/capacitor-social-login Capacitorの@capgo/capacitor-social-login Capacitorの@capgo/capacitor-passkey Capacitorの@capgo/capacitor-passkey Capacitorの@capgo/capacitor-native-biometric Capacitorの@capgo/capacitor-native-biometric Capacitorの@capgo/capacitor-native-biometric 2要素認証 2要素認証の実装詳細について