Init with Chromecast in Swift

落爺英雄遲暮 提交于 2019-12-06 17:33:27

I haven't used this library, but in the link you provide they're initializing the GCKDeviceManager like this:

self.deviceManager =
  [[GCKDeviceManager alloc] initWithDevice:self.selectedDevice
                         clientPackageName:[info objectForKey:@"CFBundleIdentifier"]];

This should translate into this swift code:

self.deviceManager = GCKDeviceManager(self.selectedDevice, clientPackageName:info["CFBundleIdentifier"])

This means your code that looks like this is invalid (or at least the GCKDeviceManager init):

var deviceScanner = GCKDeviceScanner()
var deviceManager = GCKDeviceManager()
var mediaInformation = GCKMediaInformation()
var selectedDevice = GCKDevice()

You should change it to look like this instead:

var deviceScanner : GCKDeviceScanner!
var deviceManager : GCKDeviceManager!
var mediaInformation : GCKMediaInformation!
var selectedDevice : GCKDevice!

You'll need to ensure these values are assigned to before accessing them or it'll crash. Otherwise, you can switch the types to be optionals.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!