iOS 游戏开发:AirPlay 与游戏控制器全解析
1. AirPlay 功能解析
AirPlay 是一项能为 iOS 游戏增添独特元素的功能。在使用 AirPlay 时,检测外部屏幕的连接与断开是必要的操作。苹果提供了一系列通知来处理这些事件,并通知应用进行相应处理。
要注册这些通知,可使用以下代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (handleScreenDidConnectNotification:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (handleScreenDidDisconnectNotification:) name:UIScreenDidDisconnectNotification object:nil];当屏幕连接或断开时,应用需根据需要创建或移除显示的 UIScreen。开发者要负责在不使用第二个窗口时清理它。
虽然 AirPlay 是一个相对简单且有限的主题,但它能为游戏带来独特体验。截至 2013 年初,苹果已售出 1300 万台 Apple TV,率先支持并理解 AirPlay 为产品带来的价值,将使开发者在 Apple TV 成为主流产品时占据优势。