GCKDeviceManager 类

GCKDeviceManager 类参考

概览

适用于 Cast 设备的控制器。

此类可以向 Cast 设备上运行的应用发送消息、从这些应用接收消息、启动这些应用以及关闭这些应用。

只要与 Cast 设备的连接已建立或正在创建/拆除过程中,GCKDeviceManager 实例就必须保持在范围内。在通过 connect (GCKDeviceManager) 开始连接之前,或者在调用 deviceManager:didDisconnectWithError: (GCKDeviceManagerDelegate-p)deviceManager:didSuspendConnectionWithReason: (GCKDeviceManagerDelegate-p)deviceManager:didFailToConnectWithError: (GCKDeviceManagerDelegate-p) 委托回调之后,可以安全地释放该对象。

Deprecated:
使用 GCKSessionManagerGCKCastSession 与 Cast 接收器互动。

此类继承 NSObject。

实例方法摘要

(instancetype) - initWithDevice:clientPackageName:
 使用给定的设备构造新的 GCKDeviceManager更多…
 
(instancetype) - initWithDevice:clientPackageName:ignoreAppStateNotifications:
 指定初始化程序。更多…
 
(void) - connect
 连接到设备。更多…
 
(void) - disconnect
 断开与设备的连接。更多…
 
(void) - disconnectWithLeave:
 断开与设备的连接。更多…
 
(BOOL) - addChannel:
 添加了一个可在特定命名空间中为此设备发送和接收消息的渠道。更多…
 
(BOOL) - removeChannel:
 移除之前添加的频道。更多…
 
(NSInteger) - launchApplication:
 启动应用。更多…
 
(NSInteger) - launchApplication:withLaunchOptions:
 使用给定的启动选项启动应用。更多…
 
(NSInteger) - launchApplication:relaunchIfRunning:
 启动应用,如果应用已在运行,则可以选择重新启动。更多…
 
(NSInteger) - joinApplication:
 加入应用。更多…
 
(NSInteger) - joinApplication:sessionID:
 加入具有特定应用会话 ID 的应用。更多…
 
(BOOL) - leaveApplication
 退出当前应用。更多…
 
(NSInteger) - stopApplication
 停止所有正在运行的应用。更多…
 
(NSInteger) - stopApplicationWithSessionID:
 停止具有指定应用会话 ID 的应用。更多…
 
(NSInteger) - setVolume:
 设置系统音量。更多…
 
(NSInteger) - setMuted:
 开启或关闭静音。更多...
 
(NSInteger) - requestDeviceStatus
 请求设备的当前状态。更多…
 

房源摘要

BOOL ignoreAppStateNotifications
 相应对象是否会监听应用状态通知。更多…
 
GCKConnectionState connectionState
 设备管理器的当前连接状态。更多…
 
GCKConnectionState applicationConnectionState
 设备管理器的当前应用连接状态。更多…
 
BOOL isConnected
 如果设备管理器已与设备建立连接,则为 True。更多…
 
BOOL isConnectedToApp
 如果设备管理器已与设备上的应用建立连接,则为 True。更多…
 
BOOL isReconnecting
 如果设备管理器因可能短暂的事件(例如,应用已转到后台运行,或者存在可能通过重新连接解决的网络错误)而断开连接,则为 True。更多…
 
NSTimeInterval reconnectTimeout
 如果套接字因可能存在的暂时性错误而断开连接,系统将尝试重新连接这么长时间。更多…
 
GCKDevicedevice
 正在由相应 GCKDeviceManager 控制的设备。更多…
 
id< GCKDeviceManagerDelegatedelegate
 用于接收来自 GCKDeviceManager 的通知的委托。更多…
 
float deviceVolume
 设备的当前音量(范围为 [0.0, 1.0],如果已知);否则为 0。更多…
 
BOOL deviceMuted
 设备的当前静音状态(如果已知);否则为 NO更多…
 
GCKActiveInputStatus activeInputStatus
 设备的当前“有效输入源”状态。更多…
 
GCKStandbyStatus standbyStatus
 设备的当前“待机”状态。更多…
 
NSString * applicationSessionID
 当前连接的接收器应用的会话 ID(如果有);否则为 nil更多…
 
GCKApplicationMetadataapplicationMetadata
 接收器应用(如果存在)当前在接收器上运行的元数据;否则为 nil更多…
 
NSString * applicationStatusText
 当前正在运行的接收器应用最近报告的状态文本(如果有);否则为 nil更多…
 

方法详细信息

- (instancetype) initWithDevice: (GCKDevice *)  device
clientPackageName: (NSString *)  clientPackageName 

使用给定的设备构造新的 GCKDeviceManager

该对象将监听应用状态通知,并在应用进入后台时自动断开与设备的连接,并在应用返回前台时尝试重新连接到设备。

Parameters
deviceThe device to control.
clientPackageNameThe client package name.
- (instancetype) initWithDevice: (GCKDevice *)  device
clientPackageName: (NSString *)  clientPackageName
ignoreAppStateNotifications: (BOOL)  ignoreAppStateNotifications 

指定初始化程序。

构建用于控制指定设备的新 GCKDeviceManager

如果 ignoreAppStateNotificationsNO,对象将监听应用状态的变化,并在应用进入后台时自动与设备断开连接,并在应用返回前台时尝试重新连接到设备。

如果 ignoreAppStateNotificationsYES,则对象不会监听这些通知,应用需负责管理连接生命周期。请注意,一般来说,进入后台的 iOS 应用无法无限期地继续运行,其有效网络连接最终会被操作系统关闭。

Parameters
deviceThe device to control.
clientPackageNameThe client package name.
ignoreAppStateNotificationsWhether this object will ignore app state notifications.
- (void) connect

连接到设备。

- (void) disconnect

断开与设备的连接。

这是显式断开连接。

在调用 connect 之后,并且在所有者释放此对象之前,必须在某个时间点调用某个断开连接方法。

- (void) disconnectWithLeave: (BOOL)  leaveApplication

断开与设备的连接。

在调用 connect 之后,并且在所有者释放此对象之前,必须在某个时间点调用某个断开连接方法。

Parameters
leaveApplicationYES if this is an explicit disconnect that should disconnect from ("leave") the receiver application before closing the connection; NO if this is an implicit disconnect that should just close the connection.
- (BOOL) addChannel: (GCKCastChannel *)  channel

添加了一个可在特定命名空间中为此设备发送和接收消息的渠道。

Parameters
channelThe channel.
返回
如果已添加渠道,则为
YES;如果未添加渠道,因为该命名空间已附加渠道,则为 NO
- (BOOL) removeChannel: (GCKCastChannel *)  channel

移除之前添加的频道。

Parameters
channelThe channel.
返回
如果频道已被移除,则为
;如果频道未被移除,是因为给定的频道之前未附加,则为 NOYES
- (NSInteger) launchApplication: (NSString *)  applicationID

启动应用。

Parameters
applicationIDThe application ID.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) launchApplication: (NSString *)  applicationID
withLaunchOptions: (GCKLaunchOptions *__nullable)  launchOptions 

使用给定的启动选项启动应用。

Parameters
applicationIDThe application ID.
launchOptionsThe launch options for this request. If nil, defaults will be used.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) launchApplication: (NSString *)  applicationID
relaunchIfRunning: (BOOL)  relaunchIfRunning 

启动应用,如果应用已在运行,则可以选择重新启动。

Deprecated:
请改用 launchApplication:withLaunchOptions:
Parameters
applicationIDThe application ID.
relaunchIfRunningIf YES, relaunches the application if it is already running instead of joining the running application.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) joinApplication: (NSString *__nullable)  applicationID

加入应用。

Parameters
applicationIDThe application ID. If nil, attempts to join whichever application is currently running; otherwise, attempts to join the specified application.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) joinApplication: (NSString *)  applicationID
sessionID: (NSString *)  sessionID 

加入具有特定应用会话 ID 的应用。

如果给定会话 ID 在接收器上不再处于有效状态,请求将失败。

Parameters
applicationIDThe application ID.
sessionIDThe application session ID.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (BOOL) leaveApplication

退出当前应用。

返回
如果消息无法发送,则为
NO
- (NSInteger) stopApplication

停止所有正在运行的应用。

返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) stopApplicationWithSessionID: (NSString *__nullable)  sessionID

停止具有指定应用会话 ID 的应用。

如果给定会话 ID 在接收器上不再处于有效状态,请求将失败。

Parameters
sessionIDThe application session ID, which may not be nil.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) setVolume: (float)  volume

设置系统音量。

Parameters
volumeThe new volume, in the range [0.0, 1.0]. Out of range values will be silently clipped.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) setMuted: (BOOL)  muted

开启或关闭静音。

Parameters
mutedWhether audio should be muted or unmuted.
返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID
- (NSInteger) requestDeviceStatus

请求设备的当前状态。

这样一来,一旦收到更新后的状态信息,所有委托状态更新回调都会被调用。

返回
请求 ID;如果无法发送请求,则返回 kGCKInvalidRequestID

媒体资源详情

- (BOOL) ignoreAppStateNotifications
readnonatomicassign

相应对象是否会监听应用状态通知。

此标志可在初始化程序中指定。默认值为 NO

- (GCKConnectionState) connectionState
readnonatomicassign

设备管理器的当前连接状态。

- (GCKConnectionState) applicationConnectionState
readnonatomicassign

设备管理器的当前应用连接状态。

- (BOOL) isConnected
readnonatomicassign

如果设备管理器已与设备建立连接,则为 True。

Deprecated:
使用 connectionState
- (BOOL) isConnectedToApp
readnonatomicassign

如果设备管理器已与设备上的应用建立连接,则为 True。

Deprecated:
使用 applicationConnectionState
- (BOOL) isReconnecting
readnonatomicassign

如果设备管理器因可能短暂的事件(例如,应用已转到后台运行,或者存在可能通过重新连接解决的网络错误)而断开连接,则为 True。

请注意,在设备管理器尝试在可能发生的暂时性事件后重新连接时,不会调用断开连接/连接回调,但属性将始终反映实际的当前状态,并且可以进行观测。

- (NSTimeInterval) reconnectTimeout
readwritenonatomicassign

如果套接字因可能存在的暂时性错误而断开连接,系统将尝试重新连接这么长时间。

默认超时时间为 15 秒。

- (GCKDevice*) device
readnonatomicassign

正由相应 GCKDeviceManager 控制的设备。

- (id<GCKDeviceManagerDelegate>) delegate
readwritenonatomicweak

用于接收来自 GCKDeviceManager 的通知的委托。

- (float) deviceVolume
readnonatomicassign

设备的当前音量(范围为 [0.0, 1.0]),如果已知;否则为 0。

- (BOOL) deviceMuted
readnonatomicassign

设备的当前静音状态(如果已知);否则为 NO

- (GCKActiveInputStatus) activeInputStatus
readnonatomicassign

设备的当前“有效输入源”状态。

- (GCKStandbyStatus) standbyStatus
readnonatomicassign

设备的当前“待机”状态。

- (NSString*) applicationSessionID
readnonatomiccopy

当前连接的接收器应用的会话 ID(如果有);否则为 nil

每次启动接收器应用(包括重新启动同一应用)时,系统都会生成一个新的唯一会话 ID,只要接收器应用继续运行,该 ID 就会一直有效。

- (GCKApplicationMetadata*) applicationMetadata
readnonatomiccopy

接收器应用当前在接收器上运行的元数据(如果有);否则为 nil

- (NSString*) applicationStatusText
readnonatomiccopy

当前正在运行的接收器应用最近报告的状态文本(如果有);否则为 nil