Ios 检测谷歌chromecast服务在应用程序中的使用情况
我试图检测谷歌chromecast服务在图书馆中的使用情况。有人找到了实现这一目标的方法吗?可以通过以下方式检测iOS设备当前是否正在向AppleTv传输数据:Ios 检测谷歌chromecast服务在应用程序中的使用情况,ios,swift,frameworks,chromecast,Ios,Swift,Frameworks,Chromecast,我试图检测谷歌chromecast服务在图书馆中的使用情况。有人找到了实现这一目标的方法吗?可以通过以下方式检测iOS设备当前是否正在向AppleTv传输数据: UIScreen.didConnectNotification, UIScreen.didDisconnectNotification 但当ann App向chromecast播放时,这两个通知都不会被触发。使用USB-C端口将iPad连接到外部显示器,以执行创造性任务。这是一个很少有人知道的功能,已经存在于所有iOS设备上 通过这少
UIScreen.didConnectNotification, UIScreen.didDisconnectNotification
但当ann App向chromecast播放时,这两个通知都不会被触发。使用USB-C端口将iPad连接到外部显示器,以执行创造性任务。这是一个很少有人知道的功能,已经存在于所有iOS设备上 通过这少量的代码,您可以监听显示器的连接/断开,并为外部显示器设置单独的窗口和视图控制器层次结构,以增强应用程序的主要内容
import UIKit
class ViewController: UIViewController {
// For demo purposes. We're just showing a string description
// of each UIScreen object on each screen's view controller
@IBOutlet var screenLabel: UILabel!
static func makeFromStoryboard() -> ViewController {
return UIStoryboard(name: "Main",
bundle: nil)
.instantiateInitialViewController() as! ViewController
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// The main window shown on the device's display
// The main storyboard will set this up automatically
var window: UIWindow?
// References to our windows that we're creating
var windowsForScreens = [UIScreen: UIWindow]()
// Create our view controller and add text to our test label
private func addViewController(to window: UIWindow, text: String) {
let vc = ViewController.makeFromStoryboard()
// When we need to finish loading the view before accessing
// the label outlet on the view controller
vc.loadViewIfNeeded()
vc.screenLabel.text = text
window.rootViewController = vc
}
// Create and set up a new window with our view controller as the root
private func setupWindow(for screen: UIScreen) {
let window = UIWindow()
addViewController(to: window, text: String(describing: screen))
window.screen = screen
window.makeKeyAndVisible()
windowsForScreens[screen] = window
}
// Hide the window and remove our reference to it so it will be deallocated
private func tearDownWindow(for screen: UIScreen) {
guard let window = windowsForScreens[screen] else { return }
window.isHidden = true
windowsForScreens[screen] = nil
}
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Set up the device's main screen UI
addViewController(to: window!, text: String(describing: UIScreen.main))
// We need to set up the other screens that are already connected
let otherScreens = UIScreen.screens.filter { $0 != UIScreen.main }
otherScreens.forEach { (screen) in
setupWindow(for: screen)
}
// Listen for the screen connection notification
// then set up the new window and attach it to the screen
NotificationCenter.default
.addObserver(forName: UIScreen.didConnectNotification,
object: nil,
queue: .main) { (notification) in
// UIKit is nice enough to hand us the screen object
// that represents the newly connected display
let newScreen = notification.object as! UIScreen
self.setupWindow(for: newScreen)
}
// Listen for the screen disconnection notification.
NotificationCenter.default.addObserver(forName: UIScreen.didDisconnectNotification,
object: nil,
queue: .main) { (notification) in
let newScreen = notification.object as! UIScreen
self.tearDownWindow(for: newScreen)
}
return true
}
}
如果这是为了检测设备连接的新屏幕,则表示如果未触发通知,则存在错误。请注意,在启动应用程序时,不会为已经存在的屏幕发送连接通知。有关更多详细信息,请查看。@jess问题在于,当您将内容强制转换到chromecast时,这不会被识别为新屏幕…Xcode 10警告:如果使用Xcode 10开发并针对运行iOS 12或更高版本的iOS设备,“访问WiFi信息”要从中发现并连接到Cast设备,需要具备此功能。是否确实将GCKCastContext和委托放在正确的位置?我没有Cast框架,也不想使用它。我只是想检测流媒体是否正在发生到一个cast设备…如果没有委托方法,我认为是不可能的。