# Advertisement
# Features
- Show ads through the Google IMA SDK with VAST (opens new window) and VMAP support
- Companion Ads
# Plugin requirements
- iOS 14 or higher
- Xcode
- Swift 5.5
- ByteArkPlayerSDK version >= 0.2.1
# Plugin installation
# CocoaPods (Recommended)
gem install cocoapods
1
- Add the ByteArk Player SDK iOS CocoaPods repo:
pod repo add byteark-player-sdk-ios-specs https://github.com/byteark/byteark-player-sdk-ios-specs.git
1
- Modify your
Podfile:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/byteark/byteark-player-sdk-ios-specs.git'
1
2
2
- Add the plugin:
pod 'ByteArkPlayerSDKAdsPlugin', '~> BYTEARK_PLAYER_SDK_ADS_PLUGIN_VERSION'
1
- Run
pod install.
# Swift Package Manager
- In Xcode, go to File > Add Packages.
- Enter
https://github.com/byteark/byteark-player-sdk-ios-ads-plugin. - Select the version.
# Usage
import UIKit
import ByteArkPlayerSDK
import ByteArkPlayerSDKAdsPlugin
class PlayerViewController: ByteArkPlayerViewController, ByteArkPlayerAdsPluginDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let adTagUrl = "<VAST_OR_VMAP_AD_TAG_URL>"
do {
// Create the Ads config
let adsConfig = try ByteArkPlayerAdsConfigBuilder(adsTagUrl: adTagUrl).build()
// Create the Ads plugin
let adsPlugin = ByteArkPlayerAdsPlugin(with: adsConfig)
// Receive ad callbacks
adsPlugin.delegate = self
// Build a player item
let item = try ByteArkPlayerItemBuilder()
.media(URL(string: "<MEDIA_URL>")!)
.title("Big Buck Bunny")
.build()
// Configure the player with the Ads plugin
let config = try ByteArkPlayerConfigBuilder()
.item(item)
.autoplay(true)
.addPlugin(plugin: adsPlugin, name: ByteArkPlayerAdsPlugin.PluginName)
.build()
player.configure(with: config)
} catch {
print(error.localizedDescription)
}
}
// MARK: - ByteArkPlayerAdsPluginDelegate
func adsLoader(_ loader: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
print("Ads loaded successfully.")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Plugin APIs
# Methods
| Name | Description |
|---|---|
func playAd(adTagUrl url: String, adType: ByteArkPlayerAdsPluginAdsType?) | Play an ad |
func skipAd() | Skip the current ad |
# Variables
| Name | Description |
|---|---|
var delegate: ByteArkPlayerAdsPluginDelegate? { get, set } | Set the Ads plugin delegate |
var isAdsPlaying : Bool { get } | Whether ads are playing |
var adMetadata: ByteArkPlayerAdMetadata? { get } | Get the current ad metadata |
# Listen to plugin events
@objc public protocol ByteArkPlayerAdsPluginDelegate {
/// Fired when ads are requested
@objc optional func adsRequest()
/// Fired when an ad starts playing
@objc optional func adsStart()
/// Fired when an ad ends
@objc optional func adsEnd()
/// Fired when all ads have completed
@objc optional func adsComplete()
/// Fired when an ad break starts
@objc optional func adsBreakStart()
/// Fired when an ad break ends
@objc optional func adsBreakEnd()
/// Fired when the viewer clicks the ad
@objc optional func adsClicked()
/// Fired when the viewer skips the ad
@objc optional func adsSkipped()
/// Fired when an ad error occurs
@objc optional func adsError(errorMessage: String?)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28