Snapping Games

The following section deals primarily with the code used in capture of live game information for SnapOdds Operator. If your use case requires game odds to be presented, the information captured by SnapOdds Operator is fed into SnapOdds Sports Media to correlate the game odds information, as described in Snapping Games and Presenting Odds

Implementation

  1. Verify the SDK is initialized.

  2. Ensure your class conforms to SnapscreenSnapDelegate

  3. Retrieve an instance of SnapViewController with your desired (or the default) SnapConfiguration and your SnapscreenSnapDelegate

  4. Present the SnapViewController (the recommended presentation is modally in a UINavigationController)

  5. Handle result in your delegate implementation

The sport event that is returned contains the SportRadar Match ID as the property externalId. Several other ID providers like Kambi, Donbest, and more are available on request.

Live Game Capture Code Example

The following code illustrates a SnapViewController with the default configuration.

let snapViewController = SnapViewController.forSportsOperator(configuration: SnapConfiguration(), snapDelegate: self)
snapViewController.isModalInPresentation = true
snapViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelSnap))
self.present(UINavigationController(rootViewController: snapViewController), animated: true, completion: nil)

If you do not want or need to customize the snapping configuration, you can also omit the configuration parameter.

Once a sporting event is successfully snapped, the following method is called in your SnapscreenSnapDelegate:

func snapscreenSnapViewController(
  _ viewController: SnapViewController, 
  didSnapSportEvent sportEvent: SportEventSnapResultEntry) {
  viewController.dismiss(animated: true, completion: nil)
  
  // This is the SportRadar Match ID by default. 
  // Other ID providers are available on request
  let externalProviderId = sportEvent.externalId
}

After a successful snap (and call of the delegate method) the SnapViewController automatically stops snapping. If you do not present any follow-up UI and you want to continue snapping, you can call continueSnapping() on the SnapViewController.

If the sporting event is not successfully snapped, the delegate method is not called, and an error message will appear in the viewfinder: "Your snap returned no results. Make sure your TV is visible in the viewfinder"

Camera Permissions Required before Presenting Snap

Applications must request user permission for camera access, and camera access is required for the app to function. For this reason, your application should be set to ask permission from the user to access the camera, and to receive said permission, before presenting the Snap UI. The following code will set your application to request and receive permission prior to opening Snap UI:

let status = AVCaptureDevice.authorizationStatus(for: .video)
switch status {
  case .authorized:
      presentSnap()
  case .notDetermined:
      AVCaptureDevice.requestAccess(for: .video) { [weak self] (granted) in
          DispatchQueue.main.async { [weak self] in
              if granted {
                  self?.presentSnap()
              } else {
                  presentAlertWithLinkToSettings()
              }
          }
      }
  case .denied: fallthrough
  case .restricted:
      presentAlertWithLinkToSettings()
  @unknown default:
      presentSnap()
}

Recommendations

Present Snap in a UINavigationController

SnapOdds recommends presentingSnapViewController in a UINavigationController. Please note that SnapViewController itself does not present any cancellation item within the UI. The developer of the application is responsible for configuring a cancel item on the presented UINavigationController.

Limit to portrait

Currently, Snap UI is optimized only for portrait orientation. We recommend that you limit the supported interface orientations for the presented UINavigationController to portrait only.

Last updated