@parazeni/cocos-admob-ios
v1.1.3
Published
A comprehensive AdMob integration for iOS apps built with Cocos Creator 3.8 or higher. Features include displaying banner ads, interstitial ads, and rewarded ads, providing a seamless advertising solution for developers.
Downloads
4
Readme
Cocos Creator 3.8 Admob iOS app
介紹
cocos-admob-ios 這個 npm 是提供給 cocos creator 3.8 版本以上的 iOS app,內有3個基礎的功能。
- 顯示橫幅廣告
- 顯示插頁廣告
- 獎勵廣告
配置設定
const config: GameCenterManagerConfig = {
/** 是否開啟日誌 */
openLog: true;
/** banner(橫幅)廣告 */
bannerAdId: "ca-app-pub-3940256099942544/2934735716",
/** 插頁式廣告 */
interstitialAdId: "ca-app-pub-3940256099942544/4411468910",
/** 獎勵廣告 */
rewardVideoAdId: "ca-app-pub-3940256099942544/1712485313",
}
// 使用 Admob 廣告前需要 initAd
AdmobAdManger.initAd(config);
使用範例
import { _decorator, Component, Label } from "cc";
import AdmobAdManger, { GameCenterManagerConfig } from "@parazeni/cocos-admob-ios";
const { ccclass, property } = _decorator;
@ccclass("AdmobManger")
export class AdmobManger extends Component {
@property({ type: Label })
public RewardLabel: Label = null;
private _count: number = 0;
start() {
const config: GameCenterManagerConfig = { openLog: true };
AdmobAdManger.initAd(config);
}
update(deltaTime: number) {}
/** 觸發顯示獎勵廣告彈窗 */
async onShowRewardedVideoAdClick(event: Event, str: string) {
console.log("觸發顯示獎勵廣告彈窗");
try {
const reward = await AdmobAdManger.showRewardedVideoAd();
console.log("弹出獎勵廣告事件", JSON.stringify(reward));
if (reward.result === "complete") {
console.log("獎勵廣告完成");
// 增加獎勵廣告次數
this._count++;
if (this.RewardLabel) {
this.RewardLabel.string = `獎勵次數:${this._count}`;
}
} else {
console.log("獎勵廣告未完成");
}
} catch (error) {
console.log("獎勵廣告錯誤", error);
}
}
/** 顯示 橫幅廣告 */
onShowBannerAdClick(event: Event, str: string) {
console.log("顯示 橫幅廣告");
AdmobAdManger.showBannerAd();
}
/** 關閉 橫幅廣告 */
onHideBannerAdClick() {
console.log("關閉 橫幅廣告");
AdmobAdManger.hideBannerAd();
}
/** 觸發 插頁式廣告 */
async onShowInterstitialAdClick(event: Event, str: string) {
console.log("觸發 插頁式廣告");
try {
let result = await AdmobAdManger.showInterstitialAd();
console.log("插頁式廣告 結果:", result);
} catch (error) {
console.log("插頁式廣告 錯誤:", error);
}
}
}