הגדרת IMA SDK ל-DAI

ערכות IMA SDK מאפשרות לשלב בקלות מודעות מולטימדיה באתרים ובאפליקציות. ‫IMA SDKs יכולים לשלוח בקשות למודעות מכל שרת מודעות שתואם ל-VAST ולנהל את ההפעלה של המודעות באפליקציות. באמצעות IMA DAI SDK, האפליקציות שולחות בקשה לסטרימינג של מודעות ותוכן וידאו – תוכן VOD או תוכן בשידור חי. לאחר מכן, ה-SDK מחזיר זרם וידאו משולב, כך שלא צריך לנהל את המעבר בין מודעה לתוכן וידאו באפליקציה.

בחירת פתרון DAI שמעניין אתכם

הצגת DAI ב-Pod

במדריך הזה מוסבר איך לשלב את IMA DAI SDK באפליקציית נגן וידאו פשוטה. אם אתם רוצים לראות או לעקוב אחרי שילוב לדוגמה, אתם יכולים להוריד את PodServingExample מ-GitHub.

סקירה כללית על IMA DAI

הטמעה של IMA DAI כוללת ארבעה רכיבי SDK עיקריים, כפי שמוסבר במדריך הזה:

  • IMAAdDisplayContainer – אובייקט קונטיינר שמוצב מעל רכיב הפעלת הווידאו ומכיל את רכיבי ממשק המשתמש של המודעה.
  • IMAAdsLoader – אובייקט שמבקש סטרימינג ומטפל באירועים שמופעלים על ידי אובייקטים של תגובות לבקשות סטרימינג. צריך ליצור רק מופע אחד של הכלי לטעינת מודעות, שאפשר לעשות בו שימוש חוזר לאורך חיי האפליקציה.
  • IMAStreamRequest IMAPodVODStreamRequest או IMAPodStreamRequest.
  • IMAStreamManager – אובייקט שמטפל בסטרימינג של הטמעת מודעות דינמיות ובאינטראקציות עם ה-Backend של DAI. מנהל השידור מטפל גם בפינגים למעקב ומעביר אירועים שקשורים לשידור ולמודעות אל בעל התוכן הדיגיטלי.

בנוסף, כדי להפעיל סטרימינג של פודים של מודעות, צריך להטמיע handler מותאם אישית של VTP. ה-handler המותאם אישית של VTP שולח את מזהה הסטרים לשותף הטכני של הווידאו (VTP) יחד עם כל מידע אחר שנדרש לו כדי להחזיר מניפסט של סטרים שמכיל גם תוכן וגם מודעות ששולבו בו. ספק ה-VTP יספק הוראות להטמעה של רכיב ה-handler המותאם אישית של ה-VTP.

דרישות מוקדמות

לפני שמתחילים, צריך:

צריך גם את הפרמטרים שמשמשים לשליחת בקשה לסטרימינג מ-IMA SDK.

פרמטרים של שידורים חיים
קוד רשת קוד הרשת של חשבון Ad Manager 360.
Custom Asset Key המפתח של נכס בהתאמה אישית שמזהה את אירוע הצגת המודעות ב-Ad Manager 360. יכול להיות שהקובץ הזה נוצר על ידי כלי לשינוי מניפסט או על ידי שותף צד שלישי להצגת מודעות בפודקאסטים.
פרמטרים של שידורי VOD
קוד רשת קוד הרשת של חשבון Ad Manager 360.

יצירת פרויקט חדש ב-Xcode

ב-Xcode, יוצרים פרויקט חדש ל-iOS באמצעות Objective-C בשם PodServingExample.

הוספת IMA DAI SDK לפרויקט Xcode

אפשר להשתמש באחת משלוש השיטות הבאות כדי להתקין את IMA DAI SDK.

התקנת ה-SDK באמצעות CocoaPods (מומלץ)

‫CocoaPods הוא כלי לניהול תלות בפרויקטים של Xcode, והוא השיטה המומלצת להתקנת IMA DAI SDK. מידע נוסף על התקנה או שימוש ב-CocoaPods זמין במאמרי העזרה של CocoaPods. אחרי שמתקינים את CocoaPods, משתמשים בהוראות הבאות כדי להתקין את IMA DAI SDK:

  1. באותה תיקייה שבה נמצא הקובץ PodServingExample.xcodeproj, יוצרים קובץ טקסט בשם Podfile ומוסיפים את ההגדרות הבאות:

    source 'https://github.com/CocoaPods/Specs.git'
    
    platform :ios, '14'
    
    target 'PodServingExample' do
      pod 'GoogleAds-IMA-iOS-SDK', '~> 3.26.1'
    end
    

  2. בספרייה שמכילה את קובץ ה-Podfile, מריצים את הפקודה:

    pod install --repo-update

התקנת ה-SDK באמצעות Swift Package Manager

החל מגרסה 3.18.4,‏ Interactive Media Ads SDK תומך ב-Swift Package Manager. כדי לייבא את חבילת Swift, פועלים לפי השלבים הבאים.

  1. ב-Xcode, מתקינים את חבילת ה-Swift של IMA DAI SDK. לשם כך, עוברים אל File > Add Packages (קובץ > הוספת חבילות).

  2. בהנחיה שמופיעה, מחפשים את מאגר IMA DAI SDK Swift Package GitHub:

    https://github.com/googleads/swift-package-manager-google-interactive-media-ads-ios
    
  3. בוחרים את הגרסה של IMA DAI SDK Swift Package שרוצים להשתמש בה. לפרויקטים חדשים, מומלץ להשתמש באפשרות עד הגרסה הראשית הבאה.

אחרי שתסיימו, פלטפורמת Xcode תטפל ביחסי התלות שבחבילה ותוריד אותם ברקע. לפרטים נוספים על הוספת תלות בחבילות, אפשר לעיין במאמר של Apple.

הורדה והתקנה של ה-SDK באופן ידני

אם אתם לא רוצים להשתמש ב-Swift Package Manager או ב-CocoaPods, אתם יכולים להוריד את IMA DAI SDK ולהוסיף אותו לפרויקט באופן ידני.

יצירת נגן וידאו פשוט

מטמיעים נגן וידאו בבקר התצוגה הראשי, באמצעות נגן AV שעטוף בתצוגת ממשק משתמש. ‫IMA SDK משתמש בתצוגת ממשק המשתמש כדי להציג רכיבי ממשק משתמש של מודעות.

Objective-C

#import "ViewController.h"

#import <AVKit/AVKit.h>

/// Content URL.
static NSString *const kBackupContentUrl =
    @"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";

@interface ViewController ()
/// Play button.
@property(nonatomic, weak) IBOutlet UIButton *playButton;

@property(nonatomic, weak) IBOutlet UIView *videoView;
/// Video player.
@property(nonatomic, strong) AVPlayer *videoPlayer;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.view.backgroundColor = [UIColor blackColor];

  // Load AVPlayer with the path to your content.
  NSURL *contentURL = [NSURL URLWithString:kBackupContentUrl];
  self.videoPlayer = [AVPlayer playerWithURL:contentURL];

  // Create a player layer for the player.
  AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];

  // Size, position, and display the AVPlayer.
  playerLayer.frame = self.videoView.layer.bounds;
  [self.videoView.layer addSublayer:playerLayer];
}

- (IBAction)onPlayButtonTouch:(id)sender {
  [self.videoPlayer play];
  self.playButton.hidden = YES;
}

@end

Swift

// Copyright 2024 Google LLC. All rights reserved.
//
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language governing
// permissions and limitations under the License.

import AVFoundation
import UIKit

class ViewController: UIViewController {

  /// Content URL.
  static let backupStreamURLString =
    "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"

  /// Play button.
  @IBOutlet private weak var playButton: UIButton!

  @IBOutlet private weak var videoView: UIView!
  /// Video player.
  private var videoPlayer: AVPlayer?

  override func viewDidLoad() {
    super.viewDidLoad()

    playButton.layer.zPosition = CGFloat(MAXFLOAT)

    // Load AVPlayer with path to our content.
    // note: this unwrap is safe because the URL is a constant string.
    let contentURL = URL(string: ViewController.backupStreamURLString)!
    videoPlayer = AVPlayer(url: contentURL)

    // Create a player layer for the player.
    let playerLayer = AVPlayerLayer(player: videoPlayer)

    // Size, position, and display the AVPlayer.
    playerLayer.frame = videoView.layer.bounds
    videoView.layer.addSublayer(playerLayer)
  }

  @IBAction func onPlayButtonTouch(_ sender: Any) {
    videoPlayer?.play()
    playButton.isHidden = true
  }
}

אתחול של הכלי לטעינת מודעות

מייבאים את IMA SDK לבקר התצוגה ומאמצים את הפרוטוקולים IMAAdsLoaderDelegate ו- IMAStreamManagerDelegate כדי לטפל באירועים של טוען המודעות ומנהל הסטרימינג.

מוסיפים את המאפיינים הפרטיים האלה כדי לאחסן רכיבים מרכזיים של IMA SDK:

  • IMAAdsLoader – מנהל את בקשות הסטרימינג במהלך מחזור החיים של האפליקציה.
  • IMAAdDisplayContainer – מטפל בהוספה ובניהול של רכיבי ממשק משתמש של מודעות.
  • IMAAVPlayerVideoDisplay - מתקשר בין IMA SDK לבין נגן המדיה ומטפל במטא-נתונים מתוזמנים.
  • IMAStreamManager – מנהל את ההפעלה של הסטרימינג ומפעיל אירועים שקשורים למודעות.

מפעילים את טוען המודעות, את מאגר המודעות ואת תצוגת הווידאו אחרי שהתצוגה נטענת.

Objective-C

@import GoogleInteractiveMediaAds;

// ...

@interface ViewController () <IMAAdsLoaderDelegate, IMAStreamManagerDelegate>
/// The entry point for the IMA DAI SDK to make DAI stream requests.
@property(nonatomic, strong) IMAAdsLoader *adsLoader;
/// The container where the SDK renders each ad's user interface elements and companion slots.
@property(nonatomic, strong) IMAAdDisplayContainer *adDisplayContainer;
/// The reference of your video player for the IMA DAI SDK to monitor playback and handle timed
/// metadata.
@property(nonatomic, strong) IMAAVPlayerVideoDisplay *imaVideoDisplay;
/// References the stream manager from the IMA DAI SDK after successful stream loading.
@property(nonatomic, strong) IMAStreamManager *streamManager;

// ...

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  // ...

  self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:nil];
  self.adsLoader.delegate = self;

  // Create an ad display container for rendering each ad's user interface elements and companion
  // slots.
  self.adDisplayContainer =
      [[IMAAdDisplayContainer alloc] initWithAdContainer:self.videoView
                                          viewController:self
                                          companionSlots:nil];

  // Create an IMAAVPlayerVideoDisplay to give the SDK access to your video player.
  self.imaVideoDisplay = [[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.videoPlayer];
}

Swift

import GoogleInteractiveMediaAds
// ...

class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAStreamManagerDelegate {
  // ...

  /// The entry point for the IMA DAI SDK to make DAI stream requests.
  private var adsLoader: IMAAdsLoader?
  /// The container where the SDK renders each ad's user interface elements and companion slots.
  private var adDisplayContainer: IMAAdDisplayContainer?
  /// The reference of your video player for the IMA DAI SDK to monitor playback and handle timed
  /// metadata.
  private var imaVideoDisplay: IMAAVPlayerVideoDisplay!
  /// References the stream manager from the IMA DAI SDK after successfully loading the DAI stream.
  private var streamManager: IMAStreamManager?

  // ...

  override func viewDidLoad() {
    super.viewDidLoad()

    // ...

    adsLoader = IMAAdsLoader(settings: nil)
    adsLoader?.delegate = self

    // Create an ad display container for rendering each ad's user interface elements and companion
    // slots.
    adDisplayContainer = IMAAdDisplayContainer(
      adContainer: videoView,
      viewController: self,
      companionSlots: nil)

    // Create an IMAAVPlayerVideoDisplay to give the SDK access to your video player.
    imaVideoDisplay = IMAAVPlayerVideoDisplay(avPlayer: videoPlayer)
  }

שליחת בקשה לסטרימינג

כשמשתמש לוחץ על לחצן ההפעלה, צריך לשלוח בקשה חדשה לשידור. משתמשים בכיתה IMAPodStreamRequest לשידורים חיים. לשידורים של סרטונים על פי דרישה, משתמשים במחלקה IMAPodVODStreamRequest.

בקשת הסטרימינג דורשת את פרמטרי הסטרימינג, וגם הפניה אל מאגר התצוגה של המודעות ואל תצוגת הווידאו.

Objective-C

- (IBAction)onPlayButtonTouch:(id)sender {
  [self requestStream];
  self.playButton.hidden = YES;
}

- (void)requestStream {
  // Create a stream request.
  IMAStreamRequest *request;
  if (kStreamType == StreamTypeLive) {
    // Live stream request. Replace the network code and custom asset key with your values.
    request = [[IMAPodStreamRequest alloc] initWithNetworkCode:kNetworkCode
                                                customAssetKey:kCustomAssetKey
                                            adDisplayContainer:self.adDisplayContainer
                                                  videoDisplay:self.imaVideoDisplay
                                         pictureInPictureProxy:nil
                                                   userContext:nil];
  } else {
    // VOD request. Replace the network code with your value.
    request = [[IMAPodVODStreamRequest alloc] initWithNetworkCode:kNetworkCode
                                               adDisplayContainer:self.adDisplayContainer
                                                     videoDisplay:self.imaVideoDisplay
                                            pictureInPictureProxy:nil
                                                      userContext:nil];
  }
  [self.adsLoader requestStreamWithRequest:request];
}

Swift

@IBAction func onPlayButtonTouch(_ sender: Any) {
  requestStream()
  playButton.isHidden = true
}

func requestStream() {
  // Create a stream request. Use one of "Livestream request" or "VOD request".
  if ViewController.requestType == StreamType.live {
    // Livestream request.
    let request = IMAPodStreamRequest(
      networkCode: ViewController.networkCode,
      customAssetKey: ViewController.customAssetKey,
      adDisplayContainer: adDisplayContainer!,
      videoDisplay: self.imaVideoDisplay,
      pictureInPictureProxy: nil,
      userContext: nil)
    adsLoader?.requestStream(with: request)
  } else {
    // VOD stream request.
    let request = IMAPodVODStreamRequest(
      networkCode: ViewController.networkCode,
      adDisplayContainer: adDisplayContainer!,
      videoDisplay: self.imaVideoDisplay,
      pictureInPictureProxy: nil,
      userContext: nil)
    adsLoader?.requestStream(with: request)
  }
}

האזנה לאירועי טעינה של שידור

הקלאס IMAAdsLoader קורא למתודות IMAAdsLoaderDelegate אם האתחול מצליח או אם בקשת הסטרימינג נכשלת.

בשיטת ההעברה adsLoadedWithData, מגדירים את IMAStreamManagerDelegate. מעבירים את מזהה מקור הנתונים ל-handler של VTP בהתאמה אישית, ומאחזרים את כתובת ה-URL של מניפסט מקור הנתונים. בשידורים חיים, טוענים את כתובת ה-URL של המניפסט לתצוגת הווידאו ומתחילים בהפעלה. לשידורי VOD, מעבירים את כתובת ה-URL של המניפסט לשיטה loadThirdPartyStream של מנהל השידורים. בשיטה הזו נשלחת בקשה לנתוני אירועים של מודעות מ-Ad Manager 360, ואז נטען מניפסט כתובת ה-URL ומתחילה ההפעלה.

בשיטת הנציג failedWithErrorData, מתעדים את השגיאה. אפשר גם להפעיל את הסטרימינג של הגיבוי. שיטות מומלצות ל-DAI

Objective-C

- (void)adsLoader:(IMAAdsLoader *)loader adsLoadedWithData:(IMAAdsLoadedData *)adsLoadedData {
  NSLog(@"Stream created with: %@.", adsLoadedData.streamManager.streamId);
  self.streamManager = adsLoadedData.streamManager;
  self.streamManager.delegate = self;

  // Build the Pod serving Stream URL.
  NSString *streamID = adsLoadedData.streamManager.streamId;
  // Your custom VTP handler takes the stream ID and returns the stream manifest URL.
  NSString *urlString = gCustomVTPHandler(streamID);
  NSURL *streamUrl = [NSURL URLWithString:urlString];
  if (kStreamType == StreamTypeLive) {
    // Load live streams directly into the AVPlayer.
    [self.imaVideoDisplay loadStream:streamUrl withSubtitles:@[]];
    [self.imaVideoDisplay play];
  } else {
    // Load VOD streams using the `loadThirdPartyStream` method in IMA SDK's stream manager.
    // The stream manager loads the stream, requests metadata, and starts playback.
    [self.streamManager loadThirdPartyStream:streamUrl streamSubtitles:@[]];
  }
}

- (void)adsLoader:(IMAAdsLoader *)loader failedWithErrorData:(IMAAdLoadingErrorData *)adErrorData {
  // Log the error and play the backup content.
  NSLog(@"AdsLoader error, code:%ld, message: %@", adErrorData.adError.code,
        adErrorData.adError.message);
  [self.videoPlayer play];
}

Swift

func adsLoader(_ loader: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
  print("DAI stream loaded. Stream session ID: \(adsLoadedData.streamManager!.streamId!)")
  streamManager = adsLoadedData.streamManager!
  streamManager!.delegate = self

  // Initialize the stream manager to handle ad click and user interactions with ad UI elements.
  streamManager!.initialize(with: nil)

  // Build the Pod serving Stream URL.
  let streamID = streamManager!.streamId
  // Your custom VTP handler takes the stream ID and returns the stream manifest URL.
  let urlString = ViewController.customVTPParser(streamID!)
  let streamUrl = URL(string: urlString)
  if ViewController.requestType == StreamType.live {
    // Live streams can be loaded directly into the AVPlayer.
    imaVideoDisplay.loadStream(streamUrl!, withSubtitles: [])
    imaVideoDisplay.play()
  } else {
    // VOD streams are loaded using the IMA SDK's stream manager.
    // The stream manager loads the stream, requests metadata, and starts playback.
    streamManager!.loadThirdPartyStream(streamUrl!, streamSubtitles: [])
  }
}

func adsLoader(_ loader: IMAAdsLoader, failedWith adErrorData: IMAAdLoadingErrorData) {
  print("Error loading DAI stream. Error message: \(adErrorData.adError.message!)")
  // Play the backup stream.
  videoPlayer.play()
}

הטמעה של handler מותאם אישית של VTP

הפונקציה לטיפול ב-VTP בהתאמה אישית שולחת את מזהה הסטרים של הצופה לשותף הטכני שלכם לסרטונים (VTP), יחד עם כל מידע אחר שה-VTP דורש כדי להחזיר מניפסט של הסטרים שמכיל גם תוכן וגם מודעות ששולבו בו. ספק ה-VTP שלכם יספק הוראות ספציפיות להטמעה של רכיב ה-VTP המותאם אישית.

לדוגמה, תבנית VTP עשויה לכלול כתובת URL של תבנית מניפסט שמכילה את המאקרו [[STREAMID]]. בדוגמה הזו, פונקציית ה-handler מוסיפה את מזהה הסטרים במקום המאקרו ומחזירה את כתובת ה-URL של המניפסט שנוצר.

Objective-C

/// Custom VTP Handler.
///
/// Returns the stream manifest URL from the video technical partner or manifest manipulator.
static NSString *(^gCustomVTPHandler)(NSString *) = ^(NSString *streamID) {
  // Insert synchronous code here to retrieve a stream manifest URL from your video tech partner
  // or manifest manipulation server.
  // This example uses a hardcoded URL template, containing a placeholder for the stream
  // ID and replaces the placeholder with the stream ID.
  NSString *manifestUrl = @"YOUR_MANIFEST_URL_TEMPLATE";
  return [manifestUrl stringByReplacingOccurrencesOfString:@"[[STREAMID]]"
                                                withString:streamID];
};

Swift

/// Custom VTP Handler.
///
/// Returns the stream manifest URL from the video technical partner or manifest manipulator.
static let customVTPParser = { (streamID: String) -> (String) in
  // Insert synchronous code here to retrieve a stream manifest URL from your video tech partner
  // or manifest manipulation server.
  // This example uses a hardcoded URL template, containing a placeholder for the stream
  // ID and replaces the placeholder with the stream ID.
  let manifestURL = "YOUR_MANIFEST_URL_TEMPLATE"
  return manifestURL.replacingOccurrences(of: "[[STREAMID]]", with: streamID)
}

האזנה לאירועים שקשורים למודעות

הפונקציה IMAStreamManager קוראת לשיטות IMAStreamManagerDelegate כדי להעביר אירועים ושגיאות של הזרמת נתונים לאפליקציה.

בדוגמה הזו, נרשום ביומן את אירועי המודעות העיקריים במסוף:

Objective-C

- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {
  NSLog(@"Ad event (%@).", event.typeString);
  switch (event.type) {
    case kIMAAdEvent_STARTED: {
      // Log extended data.
      NSString *extendedAdPodInfo = [[NSString alloc]
          initWithFormat:@"Showing ad %ld/%ld, bumper: %@, title: %@, description: %@, contentType:"
                         @"%@, pod index: %ld, time offset: %lf, max duration: %lf.",
                         (long)event.ad.adPodInfo.adPosition, (long)event.ad.adPodInfo.totalAds,
                         event.ad.adPodInfo.isBumper ? @"YES" : @"NO", event.ad.adTitle,
                         event.ad.adDescription, event.ad.contentType,
                         (long)event.ad.adPodInfo.podIndex, event.ad.adPodInfo.timeOffset,
                         event.ad.adPodInfo.maxDuration];

      NSLog(@"%@", extendedAdPodInfo);
      break;
    }
    case kIMAAdEvent_AD_BREAK_STARTED: {
      NSLog(@"Ad break started");
      break;
    }
    case kIMAAdEvent_AD_BREAK_ENDED: {
      NSLog(@"Ad break ended");
      break;
    }
    case kIMAAdEvent_AD_PERIOD_STARTED: {
      NSLog(@"Ad period started");
      break;
    }
    case kIMAAdEvent_AD_PERIOD_ENDED: {
      NSLog(@"Ad period ended");
      break;
    }
    default:
      break;
  }
}

- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdError:(IMAAdError *)error {
  NSLog(@"StreamManager error with type: %ld\ncode: %ld\nmessage: %@", error.type, error.code,
        error.message);
  [self.videoPlayer play];
}

Swift

func streamManager(_ streamManager: IMAStreamManager, didReceive event: IMAAdEvent) {
  print("Ad event \(event.typeString).")
  switch event.type {
  case IMAAdEventType.STARTED:
    // Log extended data.
    if let ad = event.ad {
      let extendedAdPodInfo = String(
        format: "Showing ad %zd/%zd, bumper: %@, title: %@, "
          + "description: %@, contentType:%@, pod index: %zd, "
          + "time offset: %lf, max duration: %lf.",
        ad.adPodInfo.adPosition,
        ad.adPodInfo.totalAds,
        ad.adPodInfo.isBumper ? "YES" : "NO",
        ad.adTitle,
        ad.adDescription,
        ad.contentType,
        ad.adPodInfo.podIndex,
        ad.adPodInfo.timeOffset,
        ad.adPodInfo.maxDuration)

      print("\(extendedAdPodInfo)")
    }
    break
  case IMAAdEventType.AD_BREAK_STARTED:
    print("Ad break started.")
    break
  case IMAAdEventType.AD_BREAK_ENDED:
    print("Ad break ended.")
    break
  case IMAAdEventType.AD_PERIOD_STARTED:
    print("Ad period started.")
    break
  case IMAAdEventType.AD_PERIOD_ENDED:
    print("Ad period ended.")
    break
  default:
    break
  }
}

func streamManager(_ streamManager: IMAStreamManager, didReceive error: IMAAdError) {
  print("StreamManager error with type: \(error.type)")
  print("code: \(error.code)")
  print("message: \(error.message ?? "Unknown Error")")
}

מחיקה של נכסי IMA DAI

כדי להפסיק את הפעלת הסטרימינג, להפסיק את כל המעקב אחר מודעות ולשחרר את כל נכסי הסטרימינג שנטענו, צריך להתקשר אל IMAStreamManager.destroy().

מפעילים את האפליקציה, ואם הפעולה מצליחה, אפשר לבקש ולהפעיל סטרימינג של DAI ב-Google באמצעות IMA SDK. כדי לקבל מידע על תכונות מתקדמות יותר של SDK, אפשר לעיין במדריכים אחרים שמופיעים בסרגל הצד הימני או בדוגמאות ב-GitHub.