1

我正在努力实现对 CarPlay 音频应用程序的支持,并尝试在模拟器中显示列表。我已经实现MPPlayableContentDataSource了,但是发现调用不一致。它在应用程序第一次在模拟器上启动时被调用,如果 CarPlay 在启动时打开,我可以通过向上滚动一个空列表来显示第一个项目以触发重绘。然而,CarPlay 似乎无法调用数据源,在随后的启动中,我看到一个空白屏幕或一个微调器,后面跟着消息Unable to connect to "AppName"。我尝试了不同的方法,但要点如下:

application: didFinishLaunchingWithOptions:

self.contentDataSource = [[MYContentDataSource alloc] init];
self.contentDelegate = [[MYContentDelegate alloc] init];
MPPlayableContentManager *contentManager = [MPPlayableContentManager sharedContentManager];
contentManager.dataSource = self.contentDataSource;
contentManager.delegate = self.contentDelegate;
[contentManager beginUpdates];
[contentManager endUpdates];

我已经玩过内容管理器的方法beginUpdates endUpdatesreloadData方法,但是这些都没有导致实际调用内容数据源。

我已经在数据源中实现了numberOfChildItemsAtIndexPathcontentItemAtIndexPath它似乎被正确调用,尽管只是在新模拟器上首次启动应用程序时。

要点:

- (NSInteger)numberOfChildItemsAtIndexPath:(NSIndexPath *)indexPath {
    return 3;
}

- (MPContentItem *)contentItemAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger categoryId = [indexPath indexAtPosition:0];
    MPContentItem *contentItem = [[MPContentItem alloc] initWithIdentifier:[NSString stringWithFormat:@"CAT-%lu", (unsigned long)categoryId]];
    contentItem.title = [NSString stringWithFormat:@"Category %lu", (unsigned long)categoryId];
    contentItem.subtitle = @"Subtitle";
    contentItem.playable = NO;
    contentItem.container = YES;
}

我也尝试过保留(或不保留)对MPPlayableContentManager.

我在实际的主机上有相同的行为。任何帮助,将不胜感激。

4

1 回答 1

2

在我的头撞墙了好一阵子之后,我得到了苹果的以下回答。事实证明,这MPRemoteCommandCenterMPNowPlayingInfoCenterCarPlay 工作所必需的。

1. Start responding to MPRemoteCommandCenter events at app launch
2. Set the MPNowPlayingInfoCenter dictionary at app launch

These are required for MPPlayableContentDataSource to function correctly.

文档中提到了它们,但不清楚目录显示是否需要它们。这解决了问题。

于 2018-01-31T13:27:40.817 回答