設定廣告插播播放
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南適用於想手動控制廣告插播播放時間的使用者。在預設實作中,SDK 會在排定的時間自動播放片中廣告。部分開發人員可能想禁止 SDK 自動播放這些廣告插播。實作手動廣告插播播放功能後,SDK 會在載入中場廣告時觸發 AD_BREAK_READY
事件,並等待您開始播放廣告插播。
必要條件
實用入門資訊
如果您仍需在應用程式中導入 IMA SDK,請參閱「開始使用」指南。
如要設定手動廣告插播播放功能,請完成下列三個步驟:
- 告知 SDK 您要控制廣告中斷播放。
- 監聽 AD_BREAK_READY 事件。
- 準備就緒後,請告知 SDK 播放廣告。
下列程式碼片段顯示「進階範例」
中實作手動廣告插播播放功能時,需要進行的修改:
- (void)setUpAdsLoader {
...
IMASettings settings = [[IMASettings alloc] init];
// Tell the SDK that you want to control ad break playback.
settings.autoPlayAdBreaks = NO;
self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];
...
}
- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {
...
switch (event.type) {
// Listen for the AD_BREAK_READY event
case kIMAAdEvent_AD_BREAK_READY:
// Tell the SDK to play ads when you're ready. To skip this ad break,
// simply return from this handler without calling [adsManager start].
[adsManager start];
break;
...
}
}
常見問題
- 導入 IMA SDK 時是否需要這個參數?
- 絕對沒有!只有在發布商不希望 IMA SDK 根據廣告規則或 VMAP 回應排定時間,自動播放中途廣告時,才需要使用這個選項。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThis guide explains how to manually control ad break playback timing within the IMA SDK for iOS apps, preventing automatic mid-roll playback.\u003c/p\u003e\n"],["\u003cp\u003eBy implementing manual ad break playback, developers can trigger mid-roll ads using the \u003ccode\u003eAD_BREAK_READY\u003c/code\u003e event and the \u003ccode\u003estart\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThis feature is optional and intended for publishers seeking greater control over ad playback timing, requiring code modifications to the IMA SDK setup and event handling.\u003c/p\u003e\n"],["\u003cp\u003eManual ad break playback involves three steps: disabling automatic ad breaks, listening for the \u003ccode\u003eAD_BREAK_READY\u003c/code\u003e event, and initiating ad playback when desired.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/interactive-media-ads/docs/sdks/android/client-side/manual_ad_playback \"View this page for the Android platform docs.\") [iOS](/interactive-media-ads/docs/sdks/ios/client-side/manual_ad_playback \"View this page for the iOS platform docs.\")\n\nThis guide is intended for users who want manual control over ad break playback timing. In a default implementation, the SDK automatically plays mid-rolls at their scheduled time. Some developers may want to prevent the SDK from playing these ad breaks automatically. By implementing manual ad break playback, the SDK fires an `AD_BREAK_READY` event when a mid-roll has been loaded, and wait on you to start the break's playback.\n\nPrerequisites\n\n\u003cbr /\u003e\n\n- iOS application with the IMA SDK implemented.\n\n\u003cbr /\u003e\n\nHelpful primers\n\nIf you still need to implement the IMA SDK in your app, check out our [Get Started guide](/interactive-media-ads/docs/sdks/ios/client-side).\n\nConfiguring Manual Ad Break Playback Configuring manual ad break playback takes three steps: \n\n1. Tell the SDK you want to control ad break playback.\n2. Listen for the AD_BREAK_READY event.\n3. Tell the SDK to play ads when you're ready.\n\nThe snippet below shows the modifications required on the [Advanced Example](//github.com/googleads/googleads-ima-ios/tree/master/Objective-C/AdvancedExample) to implement manual ad break playback: \n\n```objective-c\n- (void)setUpAdsLoader {\n ...\n IMASettings settings = [[IMASettings alloc] init];\n // Tell the SDK that you want to control ad break playback.\n settings.autoPlayAdBreaks = NO;\n self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];\n ...\n}\n\n- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent:(IMAAdEvent *)event {\n ...\n switch (event.type) {\n // Listen for the AD_BREAK_READY event\n case kIMAAdEvent_AD_BREAK_READY:\n // Tell the SDK to play ads when you're ready. To skip this ad break,\n // simply return from this handler without calling [adsManager start].\n [adsManager start];\n break;\n ...\n }\n}\n```\n\nFAQ\n\nIs this required for an IMA SDK implementation?\n: Absolutely not! This is only offered for publishers who do not want the IMA SDK to automatically play mid-roll ads when they are scheduled by your ad rules or VMAP response."]]