# Nonstop Swift SDK

## Should Watch Nonstop

Can be called to determine whether for a given user at a given time whether they should receive a Nonstop stream.

### When to call it

`shouldWatchNonstop` should be called prior to resuming episodes or movies when the user is logged in. The client should wait for a result before proceeding.

`shouldWatchNonstop` is not required for Live, VPPO clips or ShowMS clips. When called for non-valid content or when no user logged in it will simply return false.

### How to call it

```swift
Nonstop.sharedInstance.shouldWatchNonstop(contentId: "VDKA4220171", useLocalStore: false).subscribe { event in
    switch event {
        case .success (let watchNonstopResult):
            // Check result to see whether to play Nonstop or Standard
            // watchNonstopResult.shouldWatchNonstop
            // If required to watch Nonstop then pass the Access Token
            // watchNonstopResult.accessToken
        case .error (let error):
            // Something went wrong - should watch Standard
        }
}.disposed(by: disposables)
```

* **contentId** - the PartnerAPIId of the content the user has selected to watch
* **useLocalStore** - If this value is set to true, the SDK will perform a local lookup for checking whether the user has a valid purchase for this content or not. This should be used in scenarios where it is not necessary to fully verify that the user has a valid purchase, for example, when displaying a Nonstop Icon in the user's continue watching row. No `accessToken` will be returned in this case. If the value is false, the SDK performs a full check with the server as to whether the user has a valid purchase for this piece of content. This should continue to be used when the user resumes a piece of content to ensure the `accessToken` is retrieved.

#### Response is true

When the client application receives true for the `shouldWatchNonstop` property of the `watchNonstopResult` it means that the user should watch the selected content Nonstop. This could be for a number of reasons:

* because they are within their grace period for this piece of content
* because this piece of content has been given to all users by a particular sponsor

The client application should instruct the player to commence with a reduced ad load by passing the `watchNonstopResult.accessToken` into the player creation params as the "**cbp_token**" parameter.

#### Response is false or error

When the client application receives false for  `watchNonstopResult.shouldWatchNonstop`  it means that the user should watch the selected content with the standard ad load. This could be for a number of reasons:

* the user has not purchased this content
* this piece of content is not eligible to watch Nonstop
* an error has occurred that is best to be handled by just playing the stream with standard ad load

The client application should instruct the player to commence with a normal ad load by not passing any value for the "cbp_token" parameter on the player creation params.
