[Video](https://www.youtube.com/watch?v=QzUp3EHjZuo)

The Cast framework supports iOS 16 and later, and comes in both
static and dynamic frameworks.

See the [Google Cast iOS API Reference](https://developers.google.com/cast/docs/reference/ios.md.txt) for
descriptions of all classes and methods.

> [!NOTE]
> **Note:** New versions of the Cast iOS SDK XCFrameworks are now available, which support development on Apple Silicon computers.

## Xcode setup

> [!WARNING]
> **Warning:** Setting the `Apple Clang - Code Generation` `Optimization Level` flag to `-Ofast` for 'Fastest, Aggresive Optimizations' will cause apps using the Cast iOS SDK to crash due to incompatibilities with the optimizations. The SDK supports the default value `-Os` for 'Fastest, Smallest'.

1. **Add the Cast iOS SDK 4.8.6 to your project**


   If using
   [Swift Package Manager](https://developers.google.com/cast/docs/ios_sender.md.txt#swift_package_manager_setup), update the `google-cast-ios-sdk` package to version 4.8.6.


   Otherwise,
   [pull in the SDK manually](https://developers.google.com/cast/docs/ios_sender.md.txt#manual_setup).

   > [!CAUTION]
   > **Note** : If you built a custom device picker in your app, then you will need to explicitly call the `startDiscovery` method on the [`GCKDiscoveryManager`](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_discovery_manager.md.txt) class to initiate device discovery. Automatic scanning was disabled by default beginning with the v4.5.0 release of the Cast SDK.

2. **Add `NSBonjourServices` to your `Info.plist`**


   Specify `NSBonjourServices` in your `Info.plist` to
   allow local network discovery to succeed.


   You will need to add both `_googlecast._tcp` and
   `_<your-app-id>._googlecast._tcp` as services for device
   discovery to work properly.


   The appID is your receiverID, which is the same ID that is defined in your
   `GCKDiscoveryCriteria`.


   Update the following example `NSBonjourServices` definition and
   replace "ABCD1234" with your appID.

   ```
   <key>NSBonjourServices</key>
   <array>
     <string>_googlecast._tcp</string>
     <string>_ABCD1234._googlecast._tcp</string>
   </array>
   ```
3. **Add `NSLocalNetworkUsageDescription` to your
   `Info.plist`**


   We strongly recommend that you customize the message shown in the Local
   Network prompt by adding an app-specific permission string in your app's
   `Info.plist` file for the
   `NSLocalNetworkUsageDescription` such as to describe Cast
   discovery and other discovery services, like DIAL.

   ```
   <key>NSLocalNetworkUsageDescription</key>
   <string>${PRODUCT_NAME} uses the local network to discover Cast-enabled devices on your WiFi
   network.</string>
   ```


   This message will appear as part of the iOS Local Network Access dialog as
   shown in the mock.
   ![Cast Local Network Access permissions dialog image](https://developers.google.com/static/cast/images/ios14/cast-ios14-lna-dialog.png)
4. **Re-release your app to the Apple App Store**


   We recommend you also re-release your app using 4.8.6 as
   soon as possible.

### Swift Package Manager setup

The recommended way of integrating Google Cast is using
[Swift Package Manager](https://developer.apple.com/documentation/xcode/swift-packages)
(SPM). The Cast iOS SDK package is available from the
[google-cast-ios-sdk](https://github.com/googlecast/google-cast-ios-sdk)
GitHub repository.

To add the Cast iOS SDK to your project in Xcode:

1. In Xcode, select **File** \> **Add Packages...**.
2. Enter the repository URL: `https://github.com/googlecast/google-cast-ios-sdk`.
3. Select your versioning rules. For example, select **Up to Next Major
   Version** with a minimum version of 4.8.6 to receive compatible updates without unexpected breaking changes.
4. Click **Add Package**.
5. Select either the `GoogleCastDynamic` or the `GoogleCastStatic` product, and add it to your app target.

> [!WARNING]
> **Warning:** Add only one of the `GoogleCastDynamic` or `GoogleCastStatic` products to your target. Don't add both variants of the SDK to the same app.

#### Choose a framework variant

The Cast iOS SDK package provides two products:

- **`GoogleCastDynamic`** : The dynamic framework. It includes all of the asset resources required by the Cast UI components, and doesn't require any additional linker flags. Apps that support Mac Catalyst must use the dynamic framework. For more information, see [Mac Catalyst setup](https://developers.google.com/cast/docs/ios_sender.md.txt#mac_catalyst_setup).
- **`GoogleCastStatic`** : The static framework. It requires the additional setup steps described in [Static framework setup](https://developers.google.com/cast/docs/ios_sender.md.txt#static_framework_setup).

#### Static framework setup

Static frameworks can't include resource bundles. As a result, Swift Package
Manager can't automatically bundle the asset resources required by the Cast UI
components (such as UI images, storyboards, and localization files) with the
`GoogleCastStatic` product. If you add `GoogleCastStatic` to your target,
complete the following steps:

1. In your Xcode project, add the flags `-ObjC -lc++` to **Build Settings** \> **Other Linker Flags**.
2. If your app uses the Cast UI components, manually add the asset bundles to your project:
   1. Download the static library from [Downloads](https://developers.google.com/cast/docs/ios_sender.md.txt#downloads). Make sure that the version of the static library matches the version of the package that you added.
   2. Locate the `Resources` folder in the unzipped directory and drag all of the `.bundle` files into your Xcode project. Check 'Copy all items if needed', and add to all targets.

> [!NOTE]
> **Note:** When you update the `google-cast-ios-sdk` package to a new version, replace the asset bundles in your project with the bundles from the static library of the same version.

### CocoaPods setup

> [!WARNING]
> **Warning:** Support for CocoaPods is deprecated. Version 4.8.6 is the last update published to CocoaPods. Subsequent updates will be available using [Swift Package Manager](https://developers.google.com/cast/docs/ios_sender.md.txt#swift_package_manager_setup), and will continue to be available from direct download.

### Manual setup

The following instructions are for adding the Cast iOS SDK to your project
without using Swift Package Manager:

> [!IMPORTANT]
> **Key Point:** Starting with version 4.8.4, if you're using another library that depends on Protobuf (such as Firebase), using the static library will increase the final app size.
>
>
> We recommend that you use the static library to avoid potential version
> compatibility issues with Protobuf. However, if the size difference is a
> concern for your situation, download the dynamic library.

#### Downloads

After downloading the appropriate library below, follow the
[setup steps](https://developers.google.com/cast/docs/ios_sender.md.txt#setup_steps) to add the framework to your
project.

Cast iOS Sender SDK 4.8.6 libraries:


[Static](https://dl.google.com/dl/chromecast/sdk/ios/GoogleCastSDK-ios-4.8.6_static.zip)
[Dynamic](https://dl.google.com/dl/chromecast/sdk/ios/GoogleCastSDK-ios-4.8.6_dynamic.zip)

#### Setup steps

To install the library:

1. Download and extract the appropriate SDK for your project.
2. Set up the dynamic GoogleCastSDK library:
3. Drag the unzipped `.xcframework` into your main project in the Xcode project navigator. Check 'Copy all items if needed', and add to all targets.
4. In your Xcode target, under the `General` tab, select `Embed
   and Sign` for `GoogleCast.xcframework`. ![](https://developers.google.com/static/cast/images/xcode_dynamic_embedded.png)

If you are setting up the **dynamic** library, follow these steps in addition to
the previous steps:

1. Remove the current version of `GoogleCastSDK` if present.
2. Add the Protobuf library v3.13 or greater, following the instructions found on the [Protobuf GitHub
   repo](https://github.com/protocolbuffers/protobuf).

If you are setting up the **static** library, follow these steps in addition to
the previous steps:

1. In your Xcode project, add the flags `-ObjC -lc++` to **Build Settings** \> **Other Linker Flags** . ![](https://developers.google.com/static/cast/images/xcode_static_linker.png)
2. Locate the Resources folder in the unzipped directory and drag all of the `.bundle` files into the your project next to the `GoogleCast.xcframework` you added previously. Check 'Copy all items if needed', and add to all targets.

### Mac Catalyst setup

For Apps that support Mac Catalyst, use the dynamic library of the Cast SDK.
Follow the [manual setup process](https://developers.google.com/cast/docs/ios_sender.md.txt#manual_setup) to add the
framework to your project. Then conditionally exclude the Cast SDK from the Mac
target as mentioned in the
[Apple documentation](https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app).
Static libraries are pre-compiled for iOS architecture, which causes a linker
error when building against the Mac target.