【发布时间】:2017-08-31 13:16:28
【问题描述】:
我正在努力实现对 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 endUpdates 和 reloadData 方法,但这些方法都不会导致实际调用内容数据源。
我已经在数据源中实现了numberOfChildItemsAtIndexPath 和contentItemAtIndexPath,它们似乎被正确调用,尽管只是在新模拟器上首次启动应用程序时。
要点:
- (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 的引用。
我在实际的主机上具有相同的行为。任何帮助将不胜感激。
【问题讨论】:
-
请在bugreport.apple.com 提交错误报告。附加您的项目(或示例项目)。重现问题并在模拟器仍在启动时运行
xcrun simctl diagnose,然后将输出附加到错误报告中。 -
感谢您的注意 - 我能够在实际主机上重现该行为,因此它不是模拟器错误 - 可能是我代码中某处的错误。我将尝试构建一个示例项目来确认,如果它没有重现,则提交一个错误。目前正在处理另一个项目,但很快就会回到这个项目。
-
如果您仍需要帮助,我很乐意与您交谈,我有使用 CarPlay 的经验。请与我们联系。
标签: ios ios-simulator carplay