iOS上のGoogleログイン
__CAPGO_KEEP_0__のセットアッププロンプトをコピーして、インストール手順とこのプラグインのフルマークダウンガイドを含む。
このガイドでは、Capgo Social Login for iOSとGoogleログインをセットアップする方法を学びます。 既読の「一般的なセットアップガイド」を読んだことを前提としています。 一般的なセットアップガイド.
iOSでGoogleログインを使用する
「iOSでGoogleログインを使用する」セクションこのセクションでは、iOSでGoogleログインを設定する方法を学びます。
-
GoogleコンソールでiOSクライアントIDを作成する
-
検索バーをクリックする
-
で検索する
credentialsと検索結果のAPIs and Services2番目のアイテム(スクリーンショットに示されている2番目)
-
をクリックする
create credentials
-
を選択する
OAuth client ID
-
Select the
Application typeをiOS
-
Find the bundle ID
-
Xcodeを開く
-
Double click on
App
-
Ensure that you are on
Targets -> App
-
Find your
Bundle Identifier
-
Google Console から戻って、
Bundle Identifierに貼り付けます。Bundle ID
-
-
オプションで、App Store にアプリを公開した場合は、
App Store IDまたはTeam IDに追加します。 -
詳細をすべて入力したら、iOS クライアント作成フォームの下部にある
create
-
クライアント ID 作成確認ダイアログの
OK
-
新しく作成した iOS クライアントを開きます。
-
__CAPGO_KEEP_0__をコピーしてください
-
-
アプリのInfo.plistを変更してください
-
Xcodeを開いてInfo.plistを探してください
Info.plistファイル
-
このファイルに右クリックしてソースとして開きます code
-
下部の
Plistファイル</dict>に、
-
Info.plistファイルの
</dict>タグ
<key>CFBundleURLTypes</key><array><dict><key>CFBundleURLSchemes</key><array><string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string></array></dict></array> -
Change the
YOUR_DOT_REVERSED_IOS_CLIENT_IDを前のステップでコピーした値に変更
-
ファイルを保存する
Command + S
-
-
変更する
AppDelegate.swift-
Xcodeプロジェクトナビゲータで
-
Insert
import GoogleSignInat the top of the file
-
ファイルの中で
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
-
-
JavaScript/TypeScriptのcodeでGoogleログインを設定
-
Import
SocialLoginとCapacitorimport { SocialLogin } from '@capgo/capacitor-social-login';import { Capacitor } from '@capacitor/core'; -
初期化メソッドを呼び出してください(これは、1度だけ呼び出してください)
基本設定(オンラインモード - 最も多くのアプリケーション向けに推奨):
// 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
クリップボードにコピー
const res = await SocialLogin.login({provider: 'google',options: {}})// handle the response - contains user dataconsole.log(JSON.stringify(res))For offline mode:
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 ログインフローが正常に動作するはずです
-
既知の問題
「既知の問題」プライバシースクリーン プラグインの不互換性
「プライバシースクリーン プラグインの不互換性」Google Login プラグインは @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: {}});セクションのタイトル “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 Two-factor authentication Edit page