我正在开发我目前的iPhone音频应用程序以支持CarPlay.我已经获得Apple的批准并获得了开发权利,并观看了视频"为CarPlay启用应用程序"(https://developer.apple.com/videos/play/wwdc2017/719/).在视频中有一段Swift代码演示了如何添加CarPlay UI:
func updateCarWindow()
{
guard let screen = UIScreen.screens.first(where:
{ $0.traitCollection.userInterfaceIdiom == .carPlay })
else
{
// CarPlay is not connected
self.carWindow = nil;
return
}
// CarPlay is connected
let carWindow = UIWindow(frame: screen.bounds)
carWindow.screen = screen
carWindow.makeKeyAndVisible()
carWindow.rootViewController = CarViewController(nibName: nil, bundle: nil)
self.carWindow = carWindow
}
Run Code Online (Sandbox Code Playgroud)
我将它重新编写为Objective-C版本,如下所示:
- (void) updateCarWindow
{
NSArray *screenArray = [UIScreen screens];
for (UIScreen *screen in screenArray)
{
if (screen.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomCarPlay) // CarPlay is connected.
{
// Get the …Run Code Online (Sandbox Code Playgroud)