在swift 3

时间:2017-01-05 10:50:06

标签: ios swift swift3 chromecast

我似乎在我的项目中实现ChromeCast功能时遇到问题。 我一直在尝试在GCKDeviceScannerListener上实现UIViewController Singleton类,但是它的委托方法没有被调用。

deviceDidComeOnline的{​​{1}}方法永远不会被调用。

相反,GCKDeviceScannerListener记录器显示了一堆错误,如下所示:

chromeCast

我似乎无法弄清楚为什么我会遇到这些错误。但似乎+[NSMutableDictionary(GCKAdditions) gck_loadFromCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_nearby_devices.plist doesn't exist. +[NSMutableDictionary(GCKAdditions) gck_loadFromCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_network_cache.plist doesn't exist. scanning started +[NSMutableDictionary(GCKAdditions) gck_deleteCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_device_cache.plist doesn't exist. +[NSMutableDictionary(GCKAdditions) gck_deleteCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_device_cache_v1.plist doesn't exist. +[NSMutableDictionary(GCKAdditions) gck_deleteCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_device_cache_v2.plist doesn't exist. +[NSMutableDictionary(GCKAdditions) gck_loadFromCacheWithName:] - Device cache file file:///Users/martin/Library/Developer/CoreSimulator/Devices/318D2E15-C4B0-47D2-97AF-CD560A6063AE/data/Containers/Data/Application/C117BB98-88DA-4586-B119-0683DAD82FEB/Library/Caches/gck_device_cache_v3.plist doesn't exist 甚至从未找到我的接收设备。

我的deviceScanner代码是:

viewController

提前感谢您提供给我的任何帮助或提示。

祝你好运

更新:

我修改了我的代码库以遵循Google v3指南。 我现在在AppDelegate中实例化class ChromeCastViewController: UIViewController, GCKDeviceScannerListener, GCKDeviceManagerDelegate, GCKMediaControlChannelDelegate{ fileprivate let kCancelTitle = "Cancel" fileprivate let kDisconnectTitle:String! = "Disconnect" // Publicly available receiver to demonstrate sending messages - replace this with your // own custom app ID. fileprivate let kReceiverAppID = "XXXXXXXXX" fileprivate lazy var btnImage:UIImage = { return UIImage(named: "icon-cast-identified.png")! }() fileprivate lazy var btnImageselected:UIImage = { return UIImage(named: "icon-cast-connected.png")! }() fileprivate var deviceScanner:GCKDeviceScanner? fileprivate var deviceManager:GCKDeviceManager? fileprivate var mediaInformation:GCKMediaInformation? fileprivate var selectedDevice:GCKDevice? @IBOutlet weak var googleCastButton: UIBarButtonItem! @IBOutlet weak var backButton: UIBarButtonItem! @IBAction func backAction(_ sender: Any) { dismiss(animated: true, completion: nil) } override func viewDidLoad() { super.viewDidLoad() self.startScan() } func startScan() { let filterCriteria = GCKFilterCriteria(forAvailableApplicationWithID: kReceiverAppID) self.deviceScanner = GCKDeviceScanner(filterCriteria: filterCriteria) if let deviceScanner = self.deviceScanner { deviceScanner.add(self) deviceScanner.startScan() print("scanning started") deviceScanner.passiveScan = true } } // MARK: GCKDeviceScannerListener func deviceDidComeOnline(_ device: GCKDevice) { print("deviceDidComeOnline") print("Device found: \(device.friendlyName)"); self.updateButtonStates() } func deviceDidGoOffline(_ device: GCKDevice) { print("deviceDidGoOffline()") print("Device went away: \(device.friendlyName)"); self.updateButtonStates() } func deviceDidChange(_ device: GCKDevice) { print("deviceDidChange()"); } func updateButtonStates() { print("updateButton") if (deviceScanner!.devices.count > 0) { // Show the Cast button. navigationItem.rightBarButtonItems = [googleCastButton!] if (deviceManager != nil && deviceManager?.connectionState == GCKConnectionState.connected) { // Show the Cast button in the enabled state. googleCastButton!.tintColor = UIColor.blue } else { // Show the Cast button in the disabled state. googleCastButton!.tintColor = UIColor.gray } } else{ // Don't show Cast button. navigationItem.rightBarButtonItems = [] } } } 以使用google小部件。 但似乎GCKCastContext或与单身相关的功能在初始化后从未被调用过。我尝试将GCKCastContext添加到我的AppDelegate,看看是否检测到我的ChromeCast设备。

我的AppDelegate的代码是:

GCKDiscoveryManagerListener

函数@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, GCKLoggerDelegate,GCKDiscoveryManagerListener { var window: UIWindow? fileprivate let kReceiverAppID = "XXXXXXXXXX" var discoveryManager: GCKDiscoveryManager override init(){ let options:GCKCastOptions = GCKCastOptions(receiverApplicationID: kReceiverAppID) GCKCastContext.setSharedInstanceWith(options) self.discoveryManager = GCKCastContext.sharedInstance().discoveryManager super.init() self.discoveryManager.add(self) self.discoveryManager.passiveScan = true self.discoveryManager.startDiscovery() GCKLogger.sharedInstance().delegate = self } ..... func log(fromFunction function: UnsafePointer<Int8>, message: String) { let functionName = String(cString: function) print(functionName + " - " + message); } func didUpdateDeviceList() { print("didUpdateDeviceList with \(discoveryManager.deviceCount) devices") (0..<discoveryManager.deviceCount).forEach { index in print(index, discoveryManager.device(at: index)) } } func didStartDiscoveryForDeviceCategory(deviceCategory: String) { print("GCKDiscoveryManagerListener: \(deviceCategory)") print("FOUND: \(self.discoveryManager.hasDiscoveredDevices)") } func willUpdateDeviceList(){ print("will update device was called") } } didUpdateDeviceListdidStartDiscoveryForDeviceCategory永远不会被调用,这意味着没有找到任何Chrome设备使小部件无法使用。

再次感谢您的帮助

0 个答案:

没有答案