__CAPGO_KEEP_0__
复制一个包含安装步骤和本插件的完整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.
bun add @capgo/capacitor-admobbunx cap syncimport { AdMob } from '@capgo/capacitor-admob';API 概述
API概述start
开始初始化并启动AdMob SDK
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
请求配置配置广告请求设置
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});adCreate
创建新广告实例.__CAPGO_KEEP_0__
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adCreate({ adUnitId: 'ca-app-pub-3940256099942544/1033173712'});adIsLoaded
标题:广告已加载检查广告是否已加载并准备显示
import { AdMob } from '@capgo/capacitor-admob';
const isLoaded = await AdMob.adIsLoaded({ id: 1 });if (isLoaded) { await AdMob.adShow({ id: 1 });}adLoad
标题:加载广告加载广告
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adLoad({ id: 1 });adShow
标题:显示广告显示已加载的广告
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adShow({ id: 1 });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
标题:"AdMobConfig"AdMob 配置选项。
export type AdMobConfig = { /** Whether the app should be muted */ appMuted?: boolean; /** The app volume (0.0 to 1.0) */ appVolume?: number;};RequestConfig
《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
《MobileAdOptions》移动广告基本选项
export type MobileAdOptions = { /** The ad unit ID from AdMob */ adUnitId: string;};TrackingAuthorizationStatus
《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
《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上游发生变化时,请重新同步。
继续从入门
继续从入门如果您正在使用 入门 规划仪表板和API操作,请将其与 使用@capgo/capacitor-admob 为在使用@capgo/capacitor-admob中native能力的 API概述 为API概述的实现细节, 简介 为简介的实现细节, API密钥 为API密钥的实现细节,和 设备 为设备的实现细节。