Cast 架構支援 iOS 14 以上版本, 以及靜態和動態架構
請參閱 Google Cast iOS API 參考資料: 所有類別和方法的說明。
Xcode 設定
iOS 14
-
將 Cast iOS SDK 4.8.1 加進專案
如果使用 CocoaPods,請使用
pod update
將 4.8.1 SDK 新增至專案。否則 在 SDK 中手動提取。
-
在
Info.plist
中新增NSBonjourServices
在
Info.plist
中指定NSBonjourServices
即可: 允許在 iOS 14 上成功搜尋區域網路。您需要同時新增
_googlecast._tcp
和 將「_<your-app-id>._googlecast._tcp
」設為裝置服務 才能正常運作appID 是您的接收器 ID,這與您在
GCKDiscoveryCriteria
。更新下列範例
NSBonjourServices
定義和 取代「ABCD1234」改成您的應用程式 ID。 -
Add
NSLocalNetworkUsageDescription
to yourInfo.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 theNSLocalNetworkUsageDescription
such as to describe Cast discovery and other discovery services, like DIAL.This message will appear as part of the iOS Local Network Access dialog as shown in the mock.
-
Re-release your app to the Apple App Store
We recommend you also re-release your app using 4.8.1 as soon as possible.
iOS 13
iOS 12
Ensure that the Access WiFi Information switch in the Capabilities section of the target is set to "On".
Additionally, your provisioning profile will need to support the Access WiFi Information capability. This can be added in the Apple Developer Portal.
CocoaPods setup
The recommended way of integrating Google Cast is using
CocoaPods. For integration, use the
google-cast-sdk
CocoaPods.
To get started, follow the getting started guide.
Once CocoaPods is set up, follow the
using CocoaPods guide
to get your Podfile
created and your project ready to use with the Google Cast
SDK.
Here's an example of how to add the google-cast-sdk
CocoaPod to your
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
請為專案指定範圍,以免發生非預期的情況 請前往 podfile 指南。
在以下程式碼片段中,4.8.1 版和後續版本 主要版本 (major.minor.patch):
pod 'google-cast-sdk', '~> 4.8.1'
例如「~>」1.6.7'會包含 1.6.7 以上版本的所有版本,但不會包含 包括 2.0.0 版
手動設定
以下操作說明將協助您將 Cast iOS SDK 新增至專案 不使用 CocoaPods:
下載
下載下方合適的程式庫後, 設定步驟,將架構新增至您的 專案。
Cast iOS Sender SDK 4.8.1 程式庫:
設定步驟
如何安裝程式庫:
- 下載並解壓縮適用於專案的 SDK。
- 設定動態 GoogleCastSDK 程式庫:
-
將解壓縮的
.xcframework
拖曳到 Xcode 專案導覽工具 (如果有 Pod 專案,請勿進入 Pod 專案)。 勾選「視需要複製所有項目」,並新增到所有目標中。 -
在 Xcode 目標的 [
General
] 分頁下,為GoogleCast.xcframework
選取Embed and Sign
。
如要設定靜態資料庫,請同時按照下列步驟操作: 先前的步驟:
- 設定最低版本的 Protobuf 程式庫 3.13 版。
- 如果專案使用 CocoaPods:
-
開啟
Podfile
,並移除google-cast-sdk
(如果有的話):pod 'google-cast-sdk'
-
如果不存在,請新增
Protobuf
程式庫:pod 'Protobuf', '3.13'
-
在專案的根資料夾中執行
pod install
。 - 如果專案未使用 CocoaPods:
-
移除目前的
GoogleCastSDK
版本 (如有)。 - 新增 Protobuf 程式庫 3.13 以上版本 請按照 Protobuf GitHub 存放區。
-
在 Xcode 專案中,將
-ObjC -lc++
標記新增至 版本設定 >「Other Linker Flags」(其他連結器旗標)。 -
在解壓縮的目錄中找出「Resources」資料夾,並
拖曳
GoogleCastCoreResources.bundle
,GoogleCastUIResources.bundle
和MaterialDialogs.bundle
加到專案中,GoogleCast.xcframework
已新增勾選「視需要複製所有項目」,並新增到所有項目 目標。
Mac Catalyst 設定
如果應用程式支援 Mac Catalyst,請使用 Cast SDK 的動態程式庫。 請按照手動設定程序的說明,將 為您的專案設定架構接著有條件地從 Mac 排除 Cast SDK 先前提過 Apple 說明文件。 靜態程式庫已針對 iOS 架構預先編譯,因此會導致連結器 發生錯誤