设置 CocoaPods 后,请按照 CocoaPods 使用指南创建 Podfile,并使项目能够与 Google Cast SDK 搭配使用。
以下示例展示了如何将 google-cast-sdk CocoaPod 添加到 Podfile:
use_frameworks!
platform :ios, '14.0'
def target_pods
pod 'google-cast-sdk'
end
target 'CastVideos-objc' do
target_pods
end
target 'CastVideos-swift' do
target_pods
end
对于您的项目,您应为 pod 指定一个范围,以防止意外的破坏性更改,如 podfile 指南中所详述。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Cast framework supports iOS 14 and later and is available in static and dynamic frameworks with new XCFrameworks supporting Apple Silicon.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Cast is best integrated using CocoaPods, with manual setup as an alternative involving static or dynamic libraries.\u003c/p\u003e\n"],["\u003cp\u003eiOS 14 introduces local network permission changes requiring \u003ccode\u003eNSBonjourServices\u003c/code\u003e and \u003ccode\u003eNSLocalNetworkUsageDescription\u003c/code\u003e in your app's \u003ccode\u003eInfo.plist\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRe-release your app with Cast iOS SDK 4.8.3 to address iOS 14 network permission requirements for optimal functionality.\u003c/p\u003e\n"],["\u003cp\u003eXcode optimization level should be set to the default \u003ccode\u003e-Os\u003c/code\u003e, as \u003ccode\u003e-Ofast\u003c/code\u003e causes crashes with the Cast iOS SDK.\u003c/p\u003e\n"]]],[],null,["# Setup for Developing With the Cast Application Framework (CAF) for iOS\n\nThe Cast framework supports iOS 14 and later, and comes in both\nstatic and dynamic frameworks.\n\nSee the [Google Cast iOS API Reference](/cast/docs/reference/ios) for\ndescriptions of all classes and methods.\n| **Note:** New versions of the Cast iOS SDK XCFrameworks are now available, which support development on Apple Silicon computers.\n\nXcode setup\n-----------\n\n| **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'.\n\n### iOS 14\n\n| **iOS 14 Warning** : Changes to iOS 14 local network access permissions have impacted the Google Cast iOS SDK in a number of ways. Please see the [iOS 14 Changes](/cast/docs/ios_sender/permissions_and_discovery#ios_14) document to see how your app is affected.\n\n1. **Add the Cast iOS SDK 4.8.3 to your project**\n\n\n If using CocoaPods, use `pod update` to add the 4.8.3 SDK to your project.\n\n\n Otherwise,\n [pull in the SDK manually](https://developers.google.com/cast/docs/ios_sender#manual_setup).\n | **Note** : If you built a custom device picker in your app, then you will need to explicitly call the `startDiscovery` method on the [`GCKDiscoveryManager`](/cast/docs/reference/ios/interface_g_c_k_discovery_manager) class to initiate device discovery. Automatic scanning was disabled by default beginning with the v4.5.0 release of the Cast SDK.\n2. **Add `NSBonjourServices` to your `Info.plist`**\n\n\n Specify `NSBonjourServices` in your `Info.plist` to\n allow local network discovery to succeed on iOS 14.\n\n\n You will need to add both `_googlecast._tcp` and\n `_\u003cyour-app-id\u003e._googlecast._tcp` as services for device\n discovery to work properly.\n\n\n The appID is your receiverID, which is the same ID that is defined in your\n `GCKDiscoveryCriteria`.\n\n\n Update the following example `NSBonjourServices` definition and\n replace \"ABCD1234\" with your appID. \n\n ```scdoc\n \u003ckey\u003eNSBonjourServices\u003c/key\u003e\n \u003carray\u003e\n \u003cstring\u003e_googlecast._tcp\u003c/string\u003e\n \u003cstring\u003e_ABCD1234._googlecast._tcp\u003c/string\u003e\n \u003c/array\u003e\n ```\n3. **Add `NSLocalNetworkUsageDescription` to your\n `Info.plist`**\n\n\n We strongly recommend that you customize the message shown in the Local\n Network prompt by adding an app-specific permission string in your app's\n `Info.plist` file for the\n `NSLocalNetworkUsageDescription` such as to describe Cast\n discovery and other discovery services, like DIAL. \n\n ```genshi\n \u003ckey\u003eNSLocalNetworkUsageDescription\u003c/key\u003e\n \u003cstring\u003e${PRODUCT_NAME} uses the local network to discover Cast-enabled devices on your WiFi\n network.\u003c/string\u003e\n ```\n\n\n This message will appear as part of the iOS Local Network Access dialog as\n shown in the mock.\n4. **Re-release your app to the Apple App Store**\n\n\n We recommend you also re-release your app using 4.8.3 as\n soon as possible.\n\n### iOS 13\n\n| **iOS 13 Warning** : Apple permissions changes to iOS 13 and Xcode 11 have impacted the Google Cast iOS SDK in a number of ways. Please see the [iOS 13 Changes](/cast/docs/ios_sender/permissions_and_discovery#ios_13) document to see how your app will be impacted.\n\n### iOS 12\n\n| **iOS 12 Warning** : If developing using Xcode 10, the \"Access WiFi Information\" capability is required in order to discover and connect to Cast devices.\n\nEnsure that the **Access WiFi Information** switch in the **Capabilities**\nsection of the target is set to \"On\".\n\nAdditionally, your provisioning profile will need to support the **Access WiFi\nInformation** capability. This can be added in the\n[Apple Developer Portal](https://developer.apple.com/account/).\n\n### CocoaPods setup\n\nThe recommended way of integrating Google Cast is using\n[CocoaPods](https://cocoapods.org/). For integration, use the\n[`google-cast-sdk`](https://cocoapods.org/pods/google-cast-sdk) CocoaPods.\n\nTo get started, follow the\n[getting started guide](https://guides.cocoapods.org/using/getting-started.html).\n\nOnce CocoaPods is set up, follow the\n[using CocoaPods guide](https://guides.cocoapods.org/using/using-cocoapods.html)\nto get your `Podfile` created and your project ready to use with the Google Cast\nSDK.\n\nHere's an example of how to add the `google-cast-sdk` CocoaPod to your\n`Podfile`: \n\n use_frameworks!\n\n platform :ios, '14.0'\n\n def target_pods\n pod 'google-cast-sdk'\n end\n\n target 'CastVideos-objc' do\n target_pods\n end\n target 'CastVideos-swift' do\n target_pods\n end\n\nFor your project, you should specify a range for your pods to prevent unexpected\nbreaking changes as detailed in the\n[podfile guide](https://guides.cocoapods.org/using/the-podfile.html).\n\nIn this snippet, version 4.8.3 and the versions up to the next\nmajor version (major.minor.patch) are allowed: \n\n pod 'google-cast-sdk', '~\u003e 4.8.3'\n\nFor example, '\\~\\\u003e 1.6.7' would include all versions from 1.6.7 and up to, but not\nincluding, version 2.0.0.\n\n### Manual setup\n\nThe following instructions are for adding the Cast iOS SDK to your project\nwithout using CocoaPods:\n| **Key Point:** Starting with version 4.3.1, CocoaPods uses static libraries to avoid duplicate symbol warnings caused by a shared Protobuf library dependency when using the Firebase and Cast SDKs together. Although this change will result in a larger download, the final app size will not increase.\n|\n| If the size difference is a concern for your situation, download the\n| dynamic library to get a size similar to pre-4.3.1 versions of the CocoaPods\n| library.\n\n#### Downloads\n\nAfter downloading the appropriate library below, follow the\n[setup steps](/cast/docs/ios_sender#setup_steps) to add the framework to your\nproject.\n\nCast iOS Sender SDK 4.8.3 libraries:\n\n\n[Static](https://dl.google.com/dl/chromecast/sdk/ios/GoogleCastSDK-ios-4.8.3_static.zip)\n[Dynamic](https://dl.google.com/dl/chromecast/sdk/ios/GoogleCastSDK-ios-4.8.3_dynamic.zip)\n\n#### Setup steps\n\nTo install the library:\n\n1. Download and extract the appropriate SDK for your project.\n2. Set up the dynamic GoogleCastSDK library:\n3. Drag the unzipped `.xcframework` into your main project in the Xcode project navigator (not into the Pods project if you have one). Check 'Copy all items if needed', and add to all targets.\n4. In your Xcode target, under the `General` tab, select `Embed\n and Sign` for `GoogleCast.xcframework`.\n\nIf you are setting up the **static** library, follow these steps in addition to\nthe previous steps:\n\n1. Set up the Protobuf library with minimum version v3.13.\n 1. If your project uses CocoaPods:\n 1. Open your `Podfile` and remove the `google-cast-sdk` if present: \n\n ```text\n pod 'google-cast-sdk'\n ```\n 2. Add the `Protobuf` library if not present: \n\n ```text\n pod 'Protobuf', '3.13'\n ```\n 3. Run `pod install` in the root folder of your project.\n 2. If your project is not using CocoaPods:\n 1. Remove the current version of `GoogleCastSDK` if present.\n 2. Add the Protobuf library v3.13 or greater, following the instructions found on the [Protobuf GitHub\n repo](https://github.com/protocolbuffers/protobuf).\n2. In your Xcode project, add the flags `-ObjC -lc++` to **Build Settings** \\\u003e **Other Linker Flags** .\n3. Locate the Resources folder in the unzipped directory and drag `GoogleCastCoreResources.bundle`, `GoogleCastUIResources.bundle` and `MaterialDialogs.bundle` into the your project next to the `GoogleCast.xcframework` you added previously. Check 'Copy all items if needed', and add to all targets.\n\n### Mac Catalyst setup\n\nFor Apps that support Mac Catalyst, use the dynamic library of the Cast SDK.\nFollow the [manual setup process](/cast/docs/ios_sender#manual_setup) to add the\nframework to your project. Then conditionally exclude the Cast SDK from the Mac\ntarget as mentioned in the\n[Apple documentation](https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app).\nStatic libraries are pre-compiled for iOS architecture, which causes a linker\nerror when building against the Mac target."]]