首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS中不显示附近的cast DeviceSelection屏幕

在iOS中不显示附近的cast DeviceSelection屏幕
EN

Stack Overflow用户
提问于 2019-10-23 16:56:37
回答 1查看 688关注 0票数 4

在我的应用程序中,当我点击cast按钮时,我只能看到附近的设备选项。单击附近的设备选择选项时,应该会出现一个屏幕,其中包含所有附近的cast设备。在我的例子中,它没有出现,这应该来自google-cast-sdk本身。我使用的是pod 'google-cast-sdk','>=4.4.4‘。我正在分享我的代码,以便很容易理解问题来自哪里。

代码语言:javascript
复制
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)
}

我每次都会得到一些低于对数的东西。

代码语言:javascript
复制
 [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>.
EN

回答 1

Stack Overflow用户

发布于 2021-08-19 22:25:43

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

我猜您的iOS应用程序没有处理此权限。

您必须遵循以下链接,了解如何在使用google cast sdk的iOS发送器应用程序中启用此功能。https://developers.google.com/cast/docs/ios_sender/permissions_and_discovery

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58519079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档