开始
复制一个包含安装步骤和完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-admob`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/admob/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-admob` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
bun add @capgo/capacitor-admobbunx cap sync导入
导入部分import { AdMob } from '@capgo/capacitor-admob';API概述
API概述部分start
开始部分初始化并启动SDK AdMob。
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();configure
配置部分配置AdMob设置。
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({ appMuted: false, appVolume: 0.5});configRequest
configRequest配置广告请求设置。
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});adCreate
adCreate创建一个新广告实例。
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adCreate({ adUnitId: 'ca-app-pub-3940256099942544/1033173712'});adIsLoaded
adIsLoaded检查广告是否已加载并准备显示。
import { AdMob } from '@capgo/capacitor-admob';
const isLoaded = await AdMob.adIsLoaded({ id: 1 });if (isLoaded) { await AdMob.adShow({ id: 1 });}adLoad
adLoad加载广告。
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adLoad({ id: 1 });adShow
adShow展示已加载的广告
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adShow({ id: 1 });adHide
adHide隐藏当前显示的广告
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adHide({ id: 1 });trackingAuthorizationStatus
trackingAuthorizationStatus获取当前跟踪授权状态(仅限iOS)
import { AdMob } from '@capgo/capacitor-admob';
const { status } = await AdMob.trackingAuthorizationStatus();if (status === TrackingAuthorizationStatus.notDetermined) { await AdMob.requestTrackingAuthorization();}requestTrackingAuthorization
requestTrackingAuthorization请求用户跟踪授权(仅限iOS)
import { AdMob } from '@capgo/capacitor-admob';
const { status } = await AdMob.requestTrackingAuthorization();console.log('User tracking status:', status);类型参考
类型参考AdMobConfig
AdMob配置AdMob配置选项
export type AdMobConfig = { /** Whether the app should be muted */ appMuted?: boolean; /** The app volume (0.0 to 1.0) */ appVolume?: number;};RequestConfig
请求配置请求配置
export type RequestConfig = { /** Maximum ad content rating */ maxAdContentRating?: MaxAdContentRating; /** Whether to use the same app key */ sameAppKey?: boolean; /** Tag for child-directed treatment (true, false, or null for unspecified) */ tagForChildDirectedTreatment?: boolean | null; /** Tag for under age of consent (true, false, or null for unspecified) */ tagForUnderAgeOfConsent?: boolean | null; /** Array of test device IDs */ testDeviceIds?: string[];};MobileAdOptions
移动广告选项移动广告基础选项
export type MobileAdOptions = { /** The ad unit ID from AdMob */ adUnitId: string;};TrackingAuthorizationStatus
跟踪授权状态iOS App Tracking Transparency 授权状态跟踪
export enum TrackingAuthorizationStatus { /** User has not yet received an authorization request */ notDetermined = 0, /** User restricted, device is unable to provide authorization */ restricted = 1, /** User denied authorization */ denied = 2, /** User authorized access */ authorized = 3,}MaxAdContentRating
最大广告内容等级最大广告内容等级枚举,用于根据内容等级限制广告
export enum MaxAdContentRating { /** General Audiences */ G = 'G', /** Mature Audiences */ MA = 'MA', /** Parental Guidance */ PG = 'PG', /** Teen */ T = 'T', /** Unspecified rating */ UNSPECIFIED = '',}真实来源
真实来源本页面由插件生成 src/definitions.ts当公共 API 上游发生变化时,请重新同步
继续从 Getting Started
继续从 Getting Started如果您正在使用 开始使用 为了规划仪表板和API操作,连接它 使用@capgo/capacitor-admob 在使用@capgo/capacitor-admob中, API概述 在API概述中了解实现细节 介绍 在介绍中了解实现细节 API密钥 在API密钥中了解实现细节 设备 在设备中了解实现细节