当我从控制器创建单独的类时,Chromecast 监听器不起作用
Posted
技术标签:
【中文标题】当我从控制器创建单独的类时,Chromecast 监听器不起作用【英文标题】:Chromecast listener is not working when i create seperate class from Controller 【发布时间】:2016-05-20 10:33:03 【问题描述】:创建的类:
class ChromeCast:NSObject
//MARK:Chromecast Vars
var applicationMetadata: GCKApplicationMetadata?
var selectedDevice: GCKDevice?
var deviceManager: GCKDeviceManager?
var mediaInformation: GCKMediaInformation?
var mediaControlChannel: GCKMediaControlChannel?
var deviceScanner: GCKDeviceScanner
lazy var kReceiverAppID:String =
// You can add your own app id here that you get by registering with the
// Google Cast SDK Developer Console https://cast.google.com/publish
return kGCKMediaDefaultReceiverApplicationID
()
override init()
let filterCriteria = GCKFilterCriteria(forAvailableApplicationWithID:
kGCKMediaDefaultReceiverApplicationID)
deviceScanner = GCKDeviceScanner(filterCriteria:filterCriteria)
func startChromeCastScanning()
// Initialize device scanner
deviceScanner.addListener(self)
deviceScanner.startScan()
deviceScanner.passiveScan = false
Log.Info("Start Scanning")
extension ChromeCast: GCKDeviceScannerListener
func deviceDidComeOnline(device: GCKDevice!)
Log.Info("Device found: \(device.friendlyName)")
func deviceDidGoOffline(device: GCKDevice!)
Log.Info("Device went away: \(device.friendlyName)")
并从我的视图控制器中调用它:
someFunctionInViewController()
let chrome = ChromeCast()
chrome.startChromeCastScanning()
Delegate 没有被回调。当设备被发现时。
但是当我在视图控制器中添加所有属性和函数时,同样有效。 但我想将它与控制器分开。什么问题?
【问题讨论】:
【参考方案1】:我发现了问题 而不是本地我在我的控制器中声明 Chromecast 的全局属性
var chrome : ChromeCast?
然后从我的函数中我将其称为
func someFunction()
chrome = ChromeCast()
chrome?.startChromeCastScanning()
【讨论】:
以上是关于当我从控制器创建单独的类时,Chromecast 监听器不起作用的主要内容,如果未能解决你的问题,请参考以下文章
当我从单独的视图控制器中删除核心数据实体时,为啥会调用 UITableView 方法?
为啥当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行?