在我的应用程序中,当我点击转换按钮时,我只能看到附近的设备选项。单击附近的设备选择选项时,应出现一个包含所有附近转换设备的屏幕。就我而言,它没有出现应该来自 google-cast-sdk 本身。我在用
pod '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>.
最佳答案
如果您正在检查 iOS 14.0 设备,Apple 引入了新的本地网络权限,需要提示用户,如果授予权限,本地网络中的设备可以被发现,否则即使设备已连接您也看不到设备到同一个wifi网络。
我猜您的 iOS 应用程序中未处理此权限。
您必须按照以下链接了解如何在使用 google cast sdk 的 iOS 发件人应用程序中启用此功能。
https://developers.google.com/cast/docs/ios_sender/permissions_and_discovery
关于ios - 未在 iOS 中显示附近的转换设备选择屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58519079/