キャスト フレームワークは iOS 13 以降をサポートしており、静的フレームワークと動的フレームワークの両方があります。
すべてのクラスとメソッドの説明については、Google Cast iOS API リファレンスをご覧ください。
Xcode の設定
iOS 14
-
Cast iOS SDK 4.8.0 をプロジェクトに追加する
CocoaPods を使用する場合は、
pod update
を使用して 4.8.0 SDK をプロジェクトに追加します。それ以外の場合は、 SDK を手動で pull します。
-
NSBonjourServices
をInfo.plist
に追加するiOS 14 でローカル ネットワーク検出が成功するように、
Info.plist
にNSBonjourServices
を指定します。デバイス検出が適切に機能するには、
_googlecast._tcp
と_<your-app-id>._googlecast._tcp
の両方をサービスとして追加する必要があります。appID はレシーバー ID で、
GCKDiscoveryCriteria
で定義されている ID と同じです。次の例の
NSBonjourServices
定義を更新し、「ABCD1234」を実際の appID に置き換えます。 -
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.0 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. CocoaPods is supported for both the Universal Framework and XCFramework.
For a Universal Framework integration, use the
google-cast-sdk
and
google-cast-sdk-no-bluetooth
CocoaPods.
For an XCFramework integration, use the google-cast-sdk-xcframework
and
google-cast-sdk-no-bluetooth-xcframework
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, '13.0'
def target_pods
pod 'google-cast-sdk'
end
target 'CastVideos-objc' do
target_pods
end
target 'CastVideos-swift' do
target_pods
end
google-cast-sdk-no-bluetooth
CocoaPod を Podfile
に追加する方法の例を次に示します。
use_frameworks!
platform :ios, '13.0'
def target_pods
pod 'google-cast-sdk-no-bluetooth'
end
target 'CastVideos-objc' do
target_pods
end
target 'CastVideos-swift' do
target_pods
end
podfile ガイドで詳述されている、互換性を破る予期しない変更を防ぐために、プロジェクトには Pod の範囲を指定する必要があります。
このスニペットでは、バージョン 4.8.0 と、次のメジャー バージョン(major.minor.patch)までのバージョンが許可されています。
pod 'google-cast-sdk', '~> 4.8.0'
たとえば、「~> 1.6.7」と指定すると、1.6.7 から 2.0.0 までのすべてのバージョンが含まれます(2.0.0 は含まれません)。
手動セットアップ
CocoaPods を使用せずに、プロジェクトに Cast iOS SDK を追加する手順は次のとおりです。
ダウンロード
以下の該当するライブラリをダウンロードしたら、設定手順に沿ってフレームワークをプロジェクトに追加します。XCFrameworks の設定要件は、従来のユニバーサル フレームワークと同じです。
ユニバーサル フレームワーク
Cast iOS Sender SDK 4.8.0 ライブラリ:
Bluetooth あり: 静的 Bluetooth なし: 静的
XCFramework
Cast iOS SDK は XCFrameworks をサポートしているため、Apple シリコンを搭載した Mac パソコンでの開発と、iOS Simulator を使用したデバッグが可能です。
Cast iOS Sender SDK XCFramework 4.8.0 ライブラリ:
静的 XCFramework と Bluetooth 静的 XCFramework と Bluetooth なし
Dynamic XCFramework と Bluetooth Dynamic XCFramework と Bluetooth を使用しない
設定の手順
静的ライブラリのいずれかをインストールするには:
- プロジェクトに適した静的 SDK をダウンロードして解凍します。
- Protobuf ライブラリを最小バージョン v3.13 で設定します。
- プロジェクトで CocoaPods を使用している場合:
-
Podfile
を開き、google-cast-sdk
が存在する場合は削除します。pod 'google-cast-sdk'
-
Protobuf
ライブラリが存在しない場合は追加します。pod 'Protobuf', '3.13'
-
プロジェクトのルートフォルダで
pod install
を実行します。 - プロジェクトで CocoaPods を使用していない場合:
-
GoogleCastSDK
の現在のバージョンが存在する場合は削除します。 - Protobuf GitHub リポジトリの手順に沿って、Protobuf ライブラリ v3.13 以降を追加します。
-
解凍した
.framework
または.xcframework
を Xcode プロジェクト ナビゲータのメイン プロジェクトにドラッグします(Pod プロジェクトがある場合は移動しません)。[必要に応じてすべての項目をコピーする] チェックボックスをオンにして、すべての対象に追加します。 -
Xcode プロジェクトで、フラグ
-ObjC -lc++
を [Build Settings] > [Other Linker Flags] に追加します。 -
プロジェクトで
GoogleCast.framework
またはGoogleCast.xcframework
を右クリックし、[Finder に表示] を選択します。 -
前に追加した
GoogleCast.framework
またはGoogleCast.xcframework
の横にあるプロジェクトにGoogleCastCoreResources.bundle
とGoogleCastUIResources.bundle
をドラッグし、[必要に応じてすべてのアイテムをコピー] をオンにして、すべてのターゲットに追加します。
動的ライブラリの 1 つをインストールするには:
- プロジェクトに適した動的 SDK をダウンロードして解凍します。
- 動的な GoogleCastSDK ライブラリをセットアップします。
- プロジェクトで CocoaPods を使用している場合:
-
Podfile
を開いて、以下を削除します。pod 'google-cast-sdk'
-
プロジェクトのルートフォルダで
pod install
を実行します。 - プロジェクトで CocoaPods を使用していない場合は、現在の Google Cast ライブラリを削除します。
-
解凍した
.framework
または.xcframework
を Xcode プロジェクト ナビゲータのメイン プロジェクトにドラッグします(Pod プロジェクトがある場合は移動しません)。[必要に応じてすべての項目をコピーする] チェックボックスをオンにして、すべての対象に追加します。 -
Xcode ターゲットの [
General
] タブで、GoogleCast.framework
またはGoogleCast.xcframework
にEmbed and Sign
を選択します。
Mac Catalyst のセットアップ
Mac Catalyst をサポートするアプリの場合は、Cast SDK の動的ライブラリを使用します。 手動設定プロセスに沿って、フレームワークをプロジェクトに追加します。次に、Apple のドキュメントに記載されているとおり、Mac ターゲットから Cast SDK を条件付きで除外します。静的ライブラリは iOS アーキテクチャ用にプリコンパイルされているため、Mac ターゲットに対してビルドするとリンカー エラーが発生します。
アプリを App Store に公開する
アプリを App Store に公開する前に、シェル スクリプト strip_unused_archs.sh
を実行して、App Bundle から使用されていないアーキテクチャを削除する必要があります。このスクリプトは Cast SDK for iOS に含まれています。