> For the complete documentation index, see [llms.txt](https://docs.snapodds.com/clipshare-sdk-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snapodds.com/clipshare-sdk-docs/mobile-sdk/ios/sharing-clips.md).

# 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. Perform Snap via SnapOdds SDK (refer to <https://docs.snapodds.com/docs/mobile-sdk/ios/snapodds-operator/snapping-games>)
2. Ensure your class conforms to `ClipShareDelegate`
3. Retrieve an instance of `ClipShareViewController` with your `ClipShareDelegate`
4. Present the `ClipShareViewController`
5. 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:

```swift
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:

```swift
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`:

```swift
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`:

```swift
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`:

```swift
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`:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.snapodds.com/clipshare-sdk-docs/mobile-sdk/ios/sharing-clips.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
