iOS 用 Cast Application Framework(CAF)を使用した開発のセットアップ

キャスト フレームワークは iOS 14 以降をサポートしており、静的フレームワークと動的フレームワークの両方が用意されています。

すべてのクラスとメソッドの説明については、Google Cast iOS API リファレンスをご覧ください。

Xcode の設定

iOS 14

  1. Cast iOS SDK 4.8.1 をプロジェクトに追加する

    CocoaPods を使用している場合は、pod update を使用して 4.8.1 SDK をプロジェクトに追加します。

    それ以外の場合は、 SDK を手動で取得します。

  2. NSBonjourServicesInfo.plist に追加する

    iOS 14 でローカル ネットワークの検出を成功させるには、Info.plistNSBonjourServices を指定します。

    デバイス検出を正しく動作させるには、_googlecast._tcp_<your-app-id>._googlecast._tcp の両方をサービスとして追加する必要があります。

    appID は、receivedID です。これは、GCKDiscoveryCriteria で定義された ID と同じです。

    次の例の NSBonjourServices 定義を更新し、「ABCD1234」を実際の 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
  4. 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 ガイドで詳述されている Pod の範囲を指定する必要があります。

このスニペットでは、バージョン 4.8.1 と、次のメジャー バージョン(major.minor.patch)までのバージョンが許可されます。

pod 'google-cast-sdk', '~> 4.8.1'

たとえば、「~> 1.6.7」と指定すると、1.6.7 から 2.0.0 までのすべてのバージョンが含まれますが、バージョン 2.0.0 は含まれません。

手動セットアップ

CocoaPods を使用せずに、Cast iOS SDK をプロジェクトに追加する手順は次のとおりです。

ダウンロード

以下の該当するライブラリをダウンロードしたら、設定手順に沿ってフレームワークをプロジェクトに追加します。

Cast iOS Sender SDK 4.8.1 ライブラリ:

静的 動的

設定の手順

ライブラリをインストールするには:

  1. プロジェクトに適した SDK をダウンロードして解凍します。
  2. 動的な GoogleCastSDK ライブラリをセットアップします。
  3. 解凍した .xcframework を Xcode プロジェクト ナビゲータのメイン プロジェクトにドラッグします(Pod プロジェクトがある場合は移動しません)。[必要に応じてすべての項目をコピーする] チェックボックスをオンにして、すべてのターゲットに追加します。
  4. Xcode ターゲットの [General] タブで、GoogleCast.xcframeworkEmbed and Sign を選択します。

静的ライブラリを設定する場合は、上記の手順に加えて、以下の手順を行います。

  1. Protobuf ライブラリを最小バージョン v3.13 で設定します。
    1. プロジェクトで CocoaPods を使用している場合:
      1. Podfile を開き、google-cast-sdk が存在する場合は削除します。
        pod 'google-cast-sdk'
      2. Protobuf ライブラリが存在しない場合は追加します。
        pod 'Protobuf', '3.13'
      3. プロジェクトのルートフォルダで pod install を実行します。
    2. プロジェクトで CocoaPods を使用していない場合:
      1. GoogleCastSDK の現在のバージョンを削除します(存在する場合)。
      2. Protobuf GitHub リポジトリに記載されている手順に沿って、Protobuf ライブラリ v3.13 以降を追加します。
  2. Xcode プロジェクトで、-ObjC -lc++ フラグを [Build Settings] > [Other Linker Flags] に追加します。
  3. 解凍したディレクトリで Resources フォルダを見つけ、GoogleCastCoreResources.bundleGoogleCastUIResources.bundleMaterialDialogs.bundle をプロジェクト内の、先ほど追加した GoogleCast.xcframework の横にドラッグします。[必要に応じてすべての項目をコピーする] チェックボックスをオンにして、すべてのターゲットに追加します。

Mac Catalyst のセットアップ

Mac Catalyst をサポートするアプリの場合は、Cast SDK の動的ライブラリを使用します。 手動セットアップ プロセスに沿って、フレームワークをプロジェクトに追加します。Apple のドキュメントに記載されているとおり、条件付きで Mac ターゲットから Cast SDK を除外します。静的ライブラリは iOS アーキテクチャ用に事前コンパイルされているため、Mac ターゲットに対してビルドするとリンカーエラーが発生します。