Sharing Clips

The following section deals only with presenting the ClipShare functionality once you have performed a succcessful snap with the SnapOdds SDK.

Implementation

  1. Ensure your class conforms to ClipShareDelegate

  2. Retrieve an instance of ClipShareViewController with your ClipShareDelegate

  3. Present the ClipShareViewController

  4. Handle results in your delegate implementation

Sharing Clips

The following code illustrates how to present the ClipShareViewController. The recommended way is to present this right after you get the callback from the SnapOdds SDK about a snapped sport event, which is also reflected in this code sample:

func snapscreenSnapViewController(
  _ viewController: SnapViewController, 
  didSnapSportEvent sportEvent: SportEventSnapResultEntry) {
  
  guard let tvChannelId = sportEvent.tvChannel?.id,
        let snapTimestamp = sportEvent.timestamp,
        let authorizationHeader = Snapscreen.instance?.authorizationHeader
  else { return }
        
  let epgUnitNameFallback =
    sportEvent.sportEvent?.league
    ?? sportEvent.sportEvent?.tournament
    ?? sportEvent.sportEvent?.sport
  
  let clipShareViewController = ClipShareViewController.forSportEventSnapResultOn(
    tvChannelId: tvChannelId,
    tvChannelLogoURL: sportEvent.tvChannel?.logoURL,
    tvChannelName: sportEvent.tvChannel?.name,
    epgUnitNameFallback: epgUnitNameFallback,
    snapTimestamp: snapTimestamp,
    snapscreenAuthorizationHeader: authorizationHeader,
    clipShareDelegate: self
  )
  viewController.navigationController?.pushViewController(clipShareViewController, animated: true)
}

ClipShare tries to utilize prefetching of the frame images it displays while the users trims a clip. Additionally ClipShare requires you to provide image loading and cancellation functionality through the image loading library of your choice. The following sample implementation with SDWebImage shows how you can easily support this:

func clipShareShouldPrefetchURLs(_ imageURLs: [URL]) -> AnyObject? {
  return SDWebImagePrefetcher.shared.prefetchURLs(imageURLs)
}
    
func clipShareShouldCancelImageLoadingIn(imageView: UIImageView) {
  imageView.sd_cancelCurrentImageLoad()
}
    
func clipShareShouldLoadImageFrom(url: URL, intoImageView imageView: UIImageView, completion: ((Bool) -> Void)?) {
  let sdWebImageOptions: SDWebImageOptions = [.queryMemoryData, .queryMemoryDataSync]
  imageView.sd_setImage(with: url, placeholderImage: nil, options: sdWebImageOptions) { image, _, _, _ in
    completion?(image != nil)
  }
}

When the user successfully trims a desired clip, the following method is called in your ClipShareDelegate:

func clipShareViewController(
  _ viewController: ClipShareViewController, didCreateClip clip: Clip) {
  // add desired behaviour here
}

When the clip could not be created for any reason, the following method is called in your ClipShareDelegate:

func clipShareViewControllerDidFailCreatingClip(
  _ viewController: ClipShareViewController) {
  // add desired behaviour here
}

When no clip information for the provided Snap Result could be loaded, the following method is called in your ClipShareDelegate:

func clipShareViewControllerDidFailLoadingClip(
  _ viewController: ClipShareViewController) {
  // add desired behaviour here
}

Additionally it is (very rarely) possible that the loaded clip is not long enough to support trimming. In that case the following method is called in your ClipShareDelegate:

func clipShareViewControllerDidFailWithTooShortClip(
  _ viewController: ClipShareViewController) {
  // add desired behaviour here
}

Last updated