# OptiView Ads on iOS

This guide configures OptiView Ads in the OptiView Player iOS SDK. Version **11.9.x or later** is required.

## Prerequisites

1. Obtain an OptiView Player license compatible with OptiView Ads from the [player portal](https://portal.theoplayer.com).
2. Retrieve the Break Manifest URL for your channel. See the [Break Manifest endpoint](https://optiview.dolby.com/docs/ads/concepts/break-manifest.md#endpoint).
3. Add `THEOplayer-Integration-THEOads` to your project.

**CocoaPods**

```ruby
pod 'THEOplayer-Integration-THEOads', '~> 11.9'
```

**SwiftPM**

Add `https://github.com/THEOplayer/theoplayer-sdk-apple` and select `THEOplayerTHEOadsIntegration`.

![Screenshot of Xcode file menu](/docs/assets/images/ios-xcode-file-menu-e8f297910dd358c7a8ef64f4d7130c5b.png)

![Screenshot of SwiftPM menu](/docs/assets/images/ios-swiftpm-menu-c207b6501f931613f819a1772ab95e56.png)

![Screenshot of SwiftPM product selection](/docs/assets/images/ios-swiftpm-product-selection-e36076bec4468c2ff11c0fc2c8a629c8.png)

4. Add Google IMA. CocoaPods uses `GoogleAds-IMA-iOS-SDK`; SwiftPM uses the `GoogleInteractiveMediaAds` product.

   ![Screenshot of Xcode file menu for Google IMA](/docs/assets/images/ios-xcode-file-menu-e8f297910dd358c7a8ef64f4d7130c5b.png)

   ![Screenshot of SwiftPM menu for Google IMA](/docs/assets/images/ios-swiftpm-menu-google-21b537bc3bafd83d9d644d078ce46b17.png)

   ![Screenshot of SwiftPM Google product selection](/docs/assets/images/ios-swiftpm-product-selection-google-2fac68582649398baf8e7bdd86c51893.png)

## Step 1 — Enable OptiView Ads

Create the OptiView Ads integration and add it to the player:

```swift
import THEOplayerSDK
import THEOplayerTHEOadsIntegration

let theoads = THEOadsIntegrationFactory.createIntegration(on: theoplayer)
theoplayer.addIntegration(theoads)
```

## Step 2 — Configure the OptiView Ads source

Set a source that combines your media stream with a `THEOAdDescription`:

```swift
let typedSource = TypedSource(
    src: "YOUR-STREAM-URL",
    type: "application/x-mpegurl"
)
let theoad = THEOAdDescription(
    networkCode: "NETWORK-CODE",
    customAssetKey: "CUSTOM-ASSET-KEY",
    breakManifestUrl: URL(string: "https://us.markers.optiview.dolby.com/manifest/v1/ORG-ID/channels/CHANNEL-ID"),
    adTagParameters: ["key": "value"]
)
theoplayer.source = SourceDescription(source: typedSource, ads: [theoad])
```

The media source itself is not important to OptiView Ads: it only needs to carry timing information (such as `EXT-X-PROGRAM-DATE-TIME`) that the player can schedule breaks against.

The ad description properties:

* `breakManifestUrl` — the channel's [Break Manifest](https://optiview.dolby.com/docs/ads/concepts/break-manifest.md) URL. This is the most important part: it is where the player learns about the channel's breaks.
* `networkCode` — your Google Ad Manager network code, for [Google Pod Serving](https://optiview.dolby.com/docs/ads/integrations/google/pod-serving.md). See the [Google Ad Manager prerequisites](https://optiview.dolby.com/docs/ads/integrations/google.md).
* `customAssetKey` — the channel's custom asset key, for [Google Pod Serving](https://optiview.dolby.com/docs/ads/integrations/google/pod-serving.md).
* `adTagParameters` — player-side [ad tag parameters](https://optiview.dolby.com/docs/ads/integrations/google/pod-serving.md#ad-tag-parameters) for Google Pod Serving. Use these for values that are only known on the device, such as device identifiers; they override the break's `assetParameters` on duplicate keys.

## Step 3 — Verify playback

Start playback, then schedule a break through the API or dashboard and confirm that the ad plays out.
