Getting started (iOS SDK)

Overview


Repository

The iOS SDK is available on GitHub.


Key Features

  • Remote Player management
  • iOS 18 support
  • Verified Google IMA integration
  • OMSDK support
  • Sample Player applications & code samples
  • Fullscreen playback management
  • Access to Player events and state facilitated
  • Chromecast support

Supported versions & requirements

Swift 5+
iOS 14+
Xcode 14+

Installation

1. Create an iOS Player configuration

As a first step you need to create a custom Player configuration for your iOS application in your Dailymotion account. A unique Player Id will be generated which will be required for Player initialization in-app, accurate monetization, targeting and attribution.

The custom Player configuration can be created and managed either through the “Players” tab in the Dailymotion Studio, or programmatically via the Platform API.

📘

Note

“Picture-in-Picture”, “First time viewable”, “Aspect ratio” and “Use embedder link when sharing” features are not available on the iOS SDK and are reserved for JavaScript embeds.

⚠️

CMP implementation required to ensure monetization

Publishers in GDPR countries are required to implement a TCF2 registered CMP (Consent Management Platform) in their native app to ensure monetization. A compliant CMP must be used to use IAB TCF2 for the creation and storage of the transparency & consent string. As Dailymotion fully supports the IAB TCF2 standard, our native SDKs and our Player can access this string received from the CMP in-app.

It’s important that the consent string is available before the Player is loading. For information on how to use a CMP in-app see here.

2. Add the SDK to your project

Option 1: Using the Swift Package Manager

The Swift Package Manager  is a tool for automating the distribution of Swift code and is integrated into Xcode and the Swift compiler.

  1. Click File.
  2. Click Add Packages....
  3. Specify the git URL for Dailymotion iOS SDK: https://github.com/dailymotion/player-sdk-ios.

Option 2: Implement it manually

  1. Clone the Dailymotion iOS SDK git : https://github.com/dailymotion/player-sdk-ios
  2. Copy the **Frameworks** folder from the cloned git into your project.
  3. From Xcode select your project.
  4. Select **General** tab.
  5. Expand **Frameworks, Libraries,** and **Embedded** Content section.
  6. Open previous copied **Frameworks** folder.

Select Drag and Drop into **Frameworks**, **Libraries**, and **Embedded** section the .xcframework found in the directories **DailymotionPlayer** and **AdvertisingFramework** found there.

The frameworks added to the project target should be :

  • DailymotionPlayerSDK.xcframework
  • DailymotionAdvertisingServices.xcframework
  • GoogleInteractiveMediaAds.xcframework
  • OMSDK_Dailymotion.xcframework

You can now build your project 🚀

3. Create and add a Player view

Import Dailymotion SDK

import DailymotionPlayerSDK
import AVFoundation
import UIKit

class ViewController: UIViewController {
// Container View IBOutlet - host view for the player
  @IBOutlet weak var playerContainerView: UIView!
...

Create the Player view and add it to view hierarchy - Closure

/ Please replace the player id with your own Player ID accessed via the Dailymotion Studio or Platform API.
    Dailymotion.createPlayer(playerId: <#"xbzlf"#>, videoId: <#"x84sh87"#>, playerParameters:  DMPlayerParameters() , playerDelegate: self) { [weak self] playerView, error in
// Wait for Player initialisation and check if self is still allocated
      guard let self = self else {
        return
      }
      // Check For errors
      if let error = error {
        print("Error creating player: \(error)")
      } else {
        guard let playerView = playerView else {
          return
        }
        // Attach the created Player View to your player container View
        let constraints = [
          playerView.topAnchor.constraint(equalTo: self.playerContainerView.topAnchor, constant: 0),
          playerView.bottomAnchor.constraint(equalTo: self.playerContainerView.bottomAnchor, constant: 0),
          playerView.leadingAnchor.constraint(equalTo: self.playerContainerView.leadingAnchor, constant: 0),
          playerView.trailingAnchor.constraint(equalTo: self.playerContainerView.trailingAnchor, constant: 0)
        ]
        // Activate created constraints
        NSLayoutConstraint.activate(constraints)
      }
    }

Create the Player view and add it to view hierarchy - Async/Await

do {
      // Please replace the Player ID with your own Player ID accessed via the Dailymotion Studio or Platform API.
      let playerView = try await Dailymotion.createPlayer(playerId: <#"xbzlf"#>, videoId: <#"x84sh87"#>, playerParameters:  DMPlayerParameters() , playerDelegate: self)
      // Attach the created Player View to your player container View
      let constraints = [
        playerView.topAnchor.constraint(equalTo: self.playerContainerView.topAnchor, constant: 0),
        playerView.bottomAnchor.constraint(equalTo: self.playerContainerView.bottomAnchor, constant: 0),
        playerView.leadingAnchor.constraint(equalTo: self.playerContainerView.leadingAnchor, constant: 0),
        playerView.trailingAnchor.constraint(equalTo: self.playerContainerView.trailingAnchor, constant: 0)
      ]
      // Activate created constraints
      NSLayoutConstraint.activate(constraints)
    }
    catch {
      // Handle erros
      print("Error creating player: \(error)")
    }
}

Implement DMPlayerDelegate:

In order to get full functionality and benefit from full monetization, implementing DMPlayerDelegate is mandatory.

extension ViewController: DMPlayerDelegate {
func player(_ player: DMPlayerView, openUrl url: URL) {
    UIApplication.shared.open(url)
  }
  
  func playerWillPresentFullscreenViewController(_ player: DMPlayerView) -> UIViewController {
    return self
  }
  
  func playerWillPresentAdInParentViewController(_ player: DMPlayerView) -> UIViewController {
    return self
  }
}

Initialization method

NameInfoExample
Create PlayerTo create the player object DMPlayerView, the object will be returned in the completion closure given as a parameter. Player ID is mandatory and can be created and managed on Dailymotion StudioDailymotion.createPlayer(playerId: "PLAYERID", videoId: "VIDEOID", playerParameters: DMPlayerParameters() , playerDelegate: self)

Required configuration methods

After configuring the initialization of the player, it is required to implement the necessary methods of the protocol DMPlayerDelegate to ensure your application can manage the player in all contexts.

❗️

Warning:

The below methods need to be configured to ensure your application can manage the player in all contexts.

InfoExample
Informs the delegate that the app has to open a URL in a browser result as a user actionplayer(_ player: DMPlayerView, openUrl url: URL
Asks the delegate for a UIViewController to present the player in fullscreenplayer​Will​Present​Fullscreen​View​Controller(_:​)
Asks the delegate for a UIViewController to display an Ad dependent by a UIViewControllerplayer​Will​Present​AdInParent​View​Controller(_:​)