iOS上のGoogleログイン
このプラグインのインストール手順と全マークダウンガイドを含むセットアッププロンプトをコピーします。
このガイドでは、iOS向けのGoogleログインを設定する方法を学びます。 Capgo Social Loginの設定を完了するには、既に一般設定ガイドを読んだことを前提としています。 一般設定ガイド.
iOSでGoogleログインを使用する
Section titled “iOSでGoogleログインを使用する”iOSでGoogleログインを設定する方法を学びます。
-
GoogleコンソールでiOSクライアントIDを作成する
-
検索バーをクリックする
-
で検索する
credentialsをクリックするAPIs and Servicesの1つ(スクリーンショットの2番目)
-
Google Console の
create credentials
-
資格情報の作成メニューで
OAuth client ID
-
資格情報の作成メニューで
Application typeを選択iOS
-
バンドル ID を見つける
-
Xcode を開く
-
Xcode プロジェクト ナビゲーターで
App
-
Capgoの設定を確認してください
Targets -> App
-
Capgoの
Bundle Identifier
-
Googleコンソールに戻り、Capgoの
Bundle IdentifierにBundle ID
-
-
Capgoの
App Store IDまたはTeam IDiOSクライアント作成フォームのClient IDフィールドに -
Capgoの
create
-
クリック
OK
-
新しく作成した iOS クライアントを開く
-
以下のデータをコピーする
-
-
アプリのInfo.plistを
-
Xcodeを開いてプロジェクトナビゲータで
Info.plistファイル
-
Right click this file and open it as source code
-
ファイルの下部に
Plistタグ</dict>Info.plistファイルのdictタグ
-
Insert the following fragment just before the closing
</dict>tag
<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_IDto the value copied in the previous step
-
ファイルを保存してください
Command + S
-
-
ファイルを変更してください
AppDelegate.swift-
XcodeプロジェクトナビゲータでAppDelegate.swiftファイルを開いてください
-
ここに追加してください
import GoogleSignInAppDelegate.swiftファイルの先頭にGoogleSignIn importを追加してください
-
AppDelegate.swiftファイルで
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:])AppDelegate.swiftファイルで
-
AppDelegate.swiftファイルで
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
-
-
Setup Google login in your JavaScript/TypeScript code
-
インポート
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'}})}) -
Google ログイン機能を実装する。ボタンを作成し、次の code をクリック時に実行する
オンラインモードの場合:
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 ログインフローが正常に動作するはずです
-
問題点
セクション:「問題点」プライバシースクリーン プラグインの不互換性
セクション:「プライバシースクリーン プラグインの不互換性」Google ログイン プラグインは @capacitor/privacy-screenを使用すると、プライバシースクリーンがログイン ウェブビューを中断します。
対策: 呼び出し await PrivacyScreen.disable(); コンテキスト:Appflow 比較/移行マーケティングコピー (親キー:appflow_migration_step2)。ページ/エリア:Appflow 比較/移行マーケティングコピー。役割:ウェブサイトコピー文。見つかった場所:ionic-appflow.astro
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ログイン 認証とアカウントフローの計画に使用している場合、Cloudflare Using @capgo/capacitor-social-login for the native capability in Using @capgo/capacitor-social-login, @capgo/capacitor-social-login for the implementation detail in @capgo/capacitor-social-login, @capgo/capacitor-passkey for the implementation detail in @capgo/capacitor-passkey, @capgo/capacitor-native-biometric for the implementation detail in @capgo/capacitor-native-biometric, and 2要素認証 2要素認証の実装詳細について