<img src="https://img.shields.io/badge/%20-ENTERPRISE-B10031" style="float:left"/><br /> <img src="https://img.shields.io/badge/iOS-V4-009727?logo=apple" style="float:left"/><br />
The Google Cast framework enables a viewer to stream video and audio content to a compatible TV or sound system. By enabling the Google Cast framework in your app, a viewer can use a cast button to stream your content to a Chromecast-enabled device on a shared network connection.

The JWP iOS SDK supports casting to the Default Media Receiver and to Styled Media Receivers.
Custom receivers are not officially supported. However, if the video playback implements the same interface used in the Default Media Receiver, you may be able to initiate a casting session with a custom receiver.
To specify a receiver and start scanning for devices, pass a media receiver app ID to the `
withAppId
` argument of the `startScanningForDevices
` method of the `JWCastController
`.
<br /> <hr />
## Requirement
<br />

The JWP iOS SDK's cast integration requires that you link your app to the **dynamic** build of the Google Cast SDK. Since Google <a href="https://developers.google.com/cast/docs/developers#:~:text=CocoaPods%20uses%20static%20libraries" target="_blank">only distributes its _static_ libraries via CocoaPods</a>, there is no CocoaPods integration option — only the manual download approach described above is possible.
<br /> <hr />
## Set up permissions
If you are using Xcode 12 and targeting iOS 12+, **enable Access Wifi Information**.

Click the app target **> Capabilities > Access WiFi Information**.
Click the toggle to **ON** to enable **Access Wifi Information**.
(Guest mode only) In the **Info.plist** for your app, add `
NSBluetoothAlwaysUsageDescription
` to create a Bluetooth access request. Read _Are there changes in iOS 13 that may impact my app?_ in the <a href="#faqs">FAQs</a> section below.
If you are using the `
google-cast-sdk-no-bluetooth
` dependency, you can skip this step.(iOS 14) In the **info.plist**, add the following two keys:
`
NSBonjourServices
` with `_googlecast._tcp
` and `_<your-app-id>._googlecast._tcp
` inside the array`
NSLocalNetworkUsageDescription
`
<br /> <hr />
## Configure and enable casting
### With JWPlayerViewController
Initialize the `CastContext
` as described in Google's article, <a href="https://developers.google.com/cast/docs/ios_sender/integrate#initialize_the_cast_context" target="_blank">Integrate Cast Into Your iOS App</a>.
After initializing a `CastContext
`, casting is handled automatically by `JWPlayerViewController
`. A casting button will appear on the player, and you can respond to casting-related callbacks by overriding the `JWCastingDelegate
` methods on `JWPlayerViewController
`.

If you are trying to cast outside of `
JWPlayerViewController
`, `JWPlayerViewController
` might interfere with your implementation because the Google Cast SDK uses as singleton. To prevent `JWPlayerViewController
` from handling casting, set `handleCastingInternally
` to `false
`.
<br /> <br />
### Without JWPlayerViewController
Initialize the `
CastContext
` as described in Google's article, <a href="https://developers.google.com/cast/docs/ios_sender/integrate#initialize_the_cast_context" target="_blank">Integrate Cast Into Your iOS App</a>.In your app, create a <a href="https://sdk.jwplayer.com/ios/v4/reference/Classes/JWCastController.html" target="_blank">JWCastController</a> object and set its delegate. The delegate must adhere to the <a href="https://sdk.jwplayer.com/ios/v4/reference/Protocols/JWCastDelegate.html" target="_blank">JWCastDelegate</a> protocol and implement its delegate methods.
Call <a href="https://sdk.jwplayer.com/ios/v4/reference/Classes/JWCastController.html#/c:@M@JWPlayerKit@objc(cs)JWCastController(im)startDiscovery" target="_blank">startDiscovery()</a> to scan for devices. <br /><br />Once available devices are discovered, the event is reported to the `
JWCastDelegate
` method, `devicesAvailable:
`. This method supplies a list of available devices within range as an array of `JWCastingDevice
`.
Call the <a href="https://sdk.jwplayer.com/ios/v4/reference/Classes/JWCastController.html#/c:@M@JWPlayerKit@objc(cs)JWCastController(im)connectToDevice:" target="_blank">connectToDevice:</a> method to connect to a device. <br /><br />When a connection is established, the `
JWCastingDelegate
` method, `connectedTo:
`, is called. This signals the ability to cast the video that is reproduced by the `JWPlayer
` instance.
Call <a href="https://sdk.jwplayer.com/ios/v4/reference/Classes/JWCastController.html#/c:@M@JWPlayerKit@objc(cs)JWCastController(im)cast" target="_blank">cast()</a> on the `
JWCastController
` instance.
The JWP API controls the playback of the video being casted. The `JWPlayerDelegate
` provides the playback callbacks while casting.
<br /> <hr />
## FAQs
<details><summary><strong>Are there changes in iOS 13 that may impact my app?</strong></summary>
<br />
**Overview**
With the release of iOS 13, we want to let you know about an important change. This change is not related to JWP's SDK specifically, but we do want to make sure all of our customers aware of any third-party updates.
Apple has introduced <a href="https://developers.google.com/cast/docs/ios_sender/ios13_changes" target="_blank">stricter permissions requirements</a> in iOS 13 that enforce a tighter control for Bluetooth access.
In order to prevent failed casting sessions and application crashes, we encourage all customers to make a small change to their iOS applications. This change **does not** require development changes or SDK updates. But, it does require resubmitting your app to the App Store.
After making the following change to your app, your app users will be required to provide Bluetooth access permissions. If a user declines to give permission to Bluetooth access, the casting button will disappear and casting functionality is disabled. Playback on the device is unchanged.
<br />
**Implement the change**

<br />
Use the following steps to implement this change:
In Xcode, open **Info.plist** for your app.
Create a **Key** named **NSBluetoothAlwaysUsageDescription**. When added, this appears as **Privacy - Bluetooth Always Usage Description**.
From the **Type** options, select **String**.
Set a message noting that Bluetooth is needed to enable Google Cast as the **Value**.
<br />
You can also update the source code of **Info.plist**:
<br />
</details>
<details><summary><strong>Which features are not supported when casting with an iOS SDK player?</strong></summary>
<br />
The following features are not supported during a casting session with an iOS SDK player:
Google IMA ads
FreeWheel ads
Multiple-audio tracks or AudioTrack switching
Captions
608 captions
Sidecar captions
DVR and live streaming capabilities
<br />
Also note that Google does not support FairPlay DRM.
<br />
</details>
<br />