【问题标题】:Not showing the nearby cast DeviceSelection screen in iOS在 iOS 中不显示附近的投射设备选择屏幕
【发布时间】:2020-02-19 11:28:31
【问题描述】:

在我的应用中,当我点击投射按钮时,我只能看到附近的设备选项。单击附近的设备选择选项时,应出现一个包含所有附近投射设备的屏幕。就我而言,它没有出现应该来自 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>.

【问题讨论】:

  • 我们可以使用默认的 kGCKDefaultMediaReceiverApplicationID 还是我们需要为未发布的应用程序新生成的 ReceiverApplicationID?请告诉我。
  • 另外,我已经检查了谷歌提供的 CastVideos-swift 应用程序,该应用程序不断给出以下错误:不鼓励在分离的视图控制器上呈现视图控制器 。谁能帮我做最好的事情?
  • 确保您的设备在同一个 wifi 网络上。如果访客模式可用,则意味着您附近有一些投射设备,但不在同一个网络上。
  • 我的设备在同一个网络中。
  • @TapashMollick,您是否能够显示应用程序屏幕/视图而不是播放视频?我的意思是当前的 iOS Cast SDK 有可能吗?我到处都看到媒体播放。无法镜像(应用屏幕到外部电视),请分享您的发现。

标签: ios swift google-cast xcode11 google-cast-sdk


【解决方案1】:

如果您正在检查 iOS 14.0 设备,Apple 引入了新的本地网络权限,需要提示用户,如果授予权限,则可以发现本地网络中的设备,否则即使它们连接到同一个 wifi 网络。

我猜你的 iOS 应用没有处理这个权限。

您必须按照以下链接了解如何在使用 google cast sdk 的 iOS 发件人应用中启用此功能。 https://developers.google.com/cast/docs/ios_sender/permissions_and_discovery

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 2018-08-28
    • 1970-01-01
    • 2015-09-09
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    相关资源
    最近更新 更多