In my app when I tap on the cast button I only able to see the nearby device option. On clicking the nearby device selection options a screen with all the nearby cast devices should appear. In my case, it's not appearing which should come from the google-cast-sdk itself. I am using pod 'google-cast-sdk', '>=4.4.4'. I am sharing my code so that It would be easy to understand where is the issue coming from.
func setupCastButton() {
var castButton: GCKUICastButton! = GCKUICastButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
castButton.tintColor = .darkGray
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: castButton)
NotificationCenter.default.addObserver(self,
selector: #selector(castDeviceDidChange(notification:)),
name: NSNotification.Name.gckCastStateDidChange,
object: GCKCastContext.sharedInstance())
}
/// Keep track of the Cast state changes
@objc func castDeviceDidChange(notification _: Notification) {
print("castDeviceDidChange\(GCKCastContext.sharedInstance().castState.rawValue)")
if GCKCastContext.sharedInstance().castState != GCKCastState.noDevicesAvailable {
// Display the instructions for how to use Google Cast on the first app use.
GCKCastContext.sharedInstance().presentCastInstructionsViewControllerOnce(with: castButton)
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
initialise()
return true
}
let receiverAppID = kGCKDefaultMediaReceiverApplicationID// or "receiverAppID"
let debugLoggingEnabled = true
private var sessionManager: GCKSessionManager!
private override init() {} // To restrict multiple instance creation, as singleton deals with only one instance.
/// initialise chromecast setup
public func initialise() {
setupDiscoveryCriteria()
setUpSessionManager()
// Enable logger.
GCKLogger.sharedInstance().delegate = self
}
/// creates google cast discovery criteria
private func setupDiscoveryCriteria() {
let criteria = GCKDiscoveryCriteria(applicationID: receiverAppID)
let options = GCKCastOptions(discoveryCriteria: criteria)
GCKCastContext.setSharedInstanceWith(options)
}
/// creates the GCKSessionManager
private func setUpSessionManager() {
sessionManager = GCKCastContext.sharedInstance().sessionManager
sessionManager.add(self)
}
I am getting something below logs every time.
[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x1080e1200; frame = (0 0; 375 667); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; tag = 9992; gestureRecognizers = <NSArray: 0x2827b30c0>; layer = <CALayer: 0x28296c220>; contentOffset: {0, 0}; contentSize: {375, 73}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <GCKUIDeviceConnectionViewController: 0x1080b1c00>>
2019-10-23 14:23:08.501527+0530 [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
2019-10-23 14:23:08.501640+0530
[Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
2019-10-23 14:23:09.022438+0530 [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
2019-10-23 14:23:09.022554+0530 [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
2019-10-23 14:23:11.857338+0530 [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
2019-10-23 14:23:11.857543+0530 [Assert] button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted, UIControlStateDisabled and UIControlStateFocused. state = 4 is interpreted as UIControlStateHighlighted.
castDeviceDidChange2
2019-10-23 14:23:11.879911+0530 Presenting view controllers on detached view controllers is discouraged <UIViewController: 0x111259f40>.