Einrichtung für die Entwicklung mit dem Cast Application Framework (CAF) für iOS

Das Cast-Framework unterstützt iOS 13 und höher und ist als statisches und dynamisches Framework verfügbar.

Beschreibungen aller Klassen und Methoden finden Sie in der Google Cast iOS API-Referenz.

Xcode-Einrichtung

iOS 14

  1. Fügen Sie Ihrem Projekt das Cast iOS SDK 4.8.0 hinzu.

    Wenn Sie CocoaPods verwenden, fügen Sie Ihrem Projekt mit pod update das SDK 4.8.0 hinzu.

    Andernfalls laden Sie das SDK manuell per Pull.

  2. NSBonjourServices zu Ihrem Info.plist hinzufügen

    Gib NSBonjourServices in deinem Info.plist an, damit das lokale Netzwerk unter iOS 14 erkannt werden kann.

    Du musst sowohl _googlecast._tcp als auch _<your-app-id>._googlecast._tcp als Dienste hinzufügen, damit die Geräteerkennung richtig funktioniert.

    Die appID ist Ihre ReceiverID. Sie ist mit der ID in GCKDiscoveryCriteria identisch.

    Aktualisieren Sie die folgende NSBonjourServices-Beispieldefinition und ersetzen Sie „ABCD1234“ durch Ihre 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.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

Hier ist ein Beispiel dafür, wie Sie den CocoaPod google-cast-sdk-no-bluetooth zu Ihrem Podfile hinzufügen:

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

Sie sollten für Ihr Projekt einen Bereich für Ihre Pods angeben, um unerwartete Änderungen zu verhindern. Weitere Informationen finden Sie in der Anleitung zu Pods.

In diesem Snippet sind Version 4.8.0 sowie die Versionen bis zur nächsten Hauptversion (major.minor.patch) zulässig:

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

Beispiel: "~> 1.6.7" würde alle Versionen von 1.6.7 bis, jedoch nicht einschließlich, Version 2.0.0 einschließen.

Manuelle Einrichtung

So fügen Sie Ihrem Projekt das Cast iOS SDK hinzu, ohne CocoaPods zu verwenden:

Downloads

Nachdem Sie unten die entsprechende Bibliothek heruntergeladen haben, folgen Sie den Einrichtungsschritten, um das Framework Ihrem Projekt hinzuzufügen. Die Einrichtungsanforderungen für XCFrameworks sind dieselben wie für die alten universellen Frameworks.

Universelles Framework

Cast-Bibliotheken für iOS Sender SDK 4.8.0:

Statisch mit Bluetooth Statisch ohne Bluetooth

Dynamisch mit Bluetooth Dynamisch ohne Bluetooth

XCFramework

Das Cast iOS SDK unterstützt XCFrameworks, was die Entwicklung auf Mac-Computern mit Apple Silicon sowie die Fehlerbehebung mit dem iOS-Simulator ermöglicht.

XCFramework 4.8.0-Bibliotheken des iOS Sender SDK übertragen:

Statisches XCFramework mit Bluetooth Statisches XCFramework ohne Bluetooth

Dynamic XCFramework mit Bluetooth Dynamic XCFramework ohne Bluetooth

Einrichtungsschritte

So installieren Sie eine der static-Bibliotheken:

  1. Laden Sie das entsprechende statische SDK für Ihr Projekt herunter und entpacken Sie es.
  2. Richten Sie die Protobuf-Bibliothek mit der Mindestversion 3.13 ein.
    1. Wenn Ihr Projekt CocoaPods verwendet:
      1. Öffnen Sie Podfile und entfernen Sie google-cast-sdk (falls vorhanden):
        pod 'google-cast-sdk'
      2. Fügen Sie die Bibliothek Protobuf hinzu, falls sie nicht vorhanden ist:
        pod 'Protobuf', '3.13'
      3. Führen Sie pod install im Stammverzeichnis Ihres Projekts aus.
    2. Wenn Ihr Projekt nicht CocoaPods verwendet:
      1. Entfernen Sie die aktuelle Version von GoogleCastSDK, falls vorhanden.
      2. Fügen Sie die Protobuf-Bibliothek ab Version 3.13 hinzu. Folgen Sie dazu der Anleitung im Protobuf-GitHub-Repository.
  3. Ziehen Sie die entpackte Datei .framework oder .xcframework in Ihr Hauptprojekt im Xcode-Projektnavigator (nicht in das Pod-Projekt, falls vorhanden). Aktivieren Sie die Option „Bei Bedarf alle Elemente kopieren“ und fügen Sie sie allen Zielen hinzu.
  4. Fügen Sie in Ihrem Xcode-Projekt unter Build Settings > Other Linker Flags die Flags -ObjC -lc++ hinzu.
  5. Klicken Sie mit der rechten Maustaste auf GoogleCast.framework oder GoogleCast.xcframework in Ihrem Projekt und wählen Sie „Im Finder anzeigen“ aus.
  6. Ziehen Sie GoogleCastCoreResources.bundle und GoogleCastUIResources.bundle in das Projekt neben den zuvor hinzugefügten GoogleCast.framework oder GoogleCast.xcframework. Klicken Sie auf das Kästchen neben „Copy all items if needed“ (Alle Elemente bei Bedarf kopieren) und fügen Sie sie allen Zielen hinzu.

So installieren Sie eine der dynamischen Bibliotheken:

  1. Laden Sie das entsprechende dynamische SDK für Ihr Projekt herunter und entpacken Sie es.
  2. Richten Sie die dynamische GoogleCastSDK-Bibliothek ein:
    1. Wenn Ihr Projekt CocoaPods verwendet:
      1. Öffnen Sie Podfile und entfernen Sie Folgendes:
        pod 'google-cast-sdk'
      2. Führen Sie pod install im Stammverzeichnis Ihres Projekts aus.
    2. Wenn dein Projekt nicht CocoaPods verwendet, entferne die aktuelle Google Cast-Bibliothek.
  3. Ziehen Sie die entpackte Datei .framework oder .xcframework in Ihr Hauptprojekt im Xcode-Projektnavigator (nicht in das Pod-Projekt, falls vorhanden). Aktivieren Sie die Option „Bei Bedarf alle Elemente kopieren“ und fügen Sie sie allen Zielen hinzu.
  4. Wählen Sie in Ihrem Xcode-Ziel auf dem Tab General die Option Embed and Sign für GoogleCast.framework oder GoogleCast.xcframework aus.

Mac Catalyst einrichten

Verwende für Apps, die Mac Catalyst unterstützen, die dynamische Bibliothek des Cast SDK. Folgen Sie dem manuellen Einrichtungsprozess, um Ihrem Projekt das Framework hinzuzufügen. Schließen Sie dann das Cast SDK bedingt aus dem Mac-Ziel aus, wie in der Apple-Dokumentation beschrieben. Statische Bibliotheken werden für die iOS-Architektur vorkompiliert, was beim Erstellen für das Mac-Ziel einen Verknüpfungsfehler verursacht.

App im App Store veröffentlichen

Bevor Sie Ihre App im App Store veröffentlichen, müssen Sie das Shell-Skript strip_unused_archs.sh ausführen, um nicht verwendete Architekturen aus dem App Bundle zu entfernen. Dieses Skript befindet sich im Cast SDK for iOS.