Не показывается ближайший экран DeviceSelection в iOS - PullRequest
2 голосов
/ 23 октября 2019

В моем приложении, когда я нажимаю на кнопку приведения, я вижу только опцию ближайшего устройства. При нажатии на варианты выбора ближайшего устройства должен появиться экран со всеми соседними устройствами. В моем случае это не появляется, что должно исходить от самого google-cast-sdk. Я использую модуль 'google-cast-sdk', '> = 4.4.4'. Я делюсь своим кодом, чтобы было легко понять, откуда возникла проблема.

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)
}

Я каждый раз получаю что-то ниже логов.

 [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>.
...