无法使用GoogleCastSDK iOS 4.5.0在iOS 14上启动设备发现

问题描述

我正在尝试按照以下指南将iOS Sender App从Cast SDK v2迁移到Cast应用程序框架(CAF): https://developers.google.com/cast/docs/migrate_v2/ios_sender

iOS版本是14,我按照此页面上的说明进行操作: https://developers.google.com/cast/docs/ios_sender/ios_permissions_changes

这是我已经完成的工作:

  1. 手动将Cast iOS SDK 4.5.0(无蓝牙)添加到我的项目中。

  2. 将NSBonjourServices添加到我的Info.plist中,其中XXXXXXXX是我的自定义接收器应用程序ID:

<key>NSBonjourServices</key>
<array>
  <string>_googlecast._tcp</string>
  <string>_XXXXXXXX._googlecast._tcp</string>
</array>
  1. 在我的Info.plist中添加了NSLocalNetworkUsageDescription。

  2. 添加了“访问WiFi信息”权利:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.networking.wifi-info</key>
    <true/>
</dict>
</plist>

我的应用程序使用自定义UI选择投放设备,因此我不使用GCKUICastButton。 这是我的代码在主UIViewController的viewDidLoad方法中运行,该方法也是GCKdiscoveryManagerListener:

[GCKLogger sharedInstance].delegate = self;
    
GCKdiscoveryCriteria* discoveryCriteria = [[GCKdiscoveryCriteria alloc] initWithApplicationID:kMyReceiverappid];
GCKCastOptions *options = [[GCKCastOptions alloc] initWithdiscoveryCriteria:discoveryCriteria];
options.startdiscoveryAfterFirstTapOnCastButton = NO;
options.disablediscoveryAutostart = NO;
[GCKCastContext setSharedInstanceWithOptions:options];

GCKdiscoveryManager* chromecastdiscoveryManager = [GCKCastContext sharedInstance].discoveryManager;
[chromecastdiscoveryManager addListener:self];
[chromecastdiscoveryManager startdiscovery];

结果:从未调用过GCKDeviceManagerDelegate方法(didStartdiscoveryForDeviceCategory,didInsertDevice,didRemoveDevice)。 在调试控制台上,我看到此消息(如果它与我的问题有任何联系):

CoreData model CastFrameworkDB.momd not found at (null),-[GCKDatabase initWithEmpty:inMemory:runtimeConfiguration:]_block_invoke,GCKDatabase.m:217
Can't initialize database because the model can't be found in bundle,aborting,GCKDatabase.m:218

任何帮助将不胜感激!

解决方法

XCode不会自动将 GoogleCast.framework捆绑包文件添加到项目中,这就是此错误的原因。

要纠正此问题,您将必须手动添加捆绑文件。为此,请转到项目设置“构建阶段”->“复制捆绑资源”->“添加项目”->“添加其他”。然后在 GoogleCast.framework 文件夹中找到 GoogleCastCoreResources.bundle GoogleCastUIResources.bundle 。选择它们并添加。

这应该可以解决问题。