【问题标题】:MPPlayableContentDataSource called inconsistentlyMPPlayableContentDataSource 调用不一致
【发布时间】: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


【解决方案1】:

我的头在墙上撞了半天,我得到了苹果的以下答复。事实证明,CarPlay 需要 MPRemoteCommandCenter 和 MPNowPlayingInfoCenter 才能工作。

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.

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

【讨论】:

  • 步骤 1 和 2 不需要在屏幕上显示内容项。一旦您触摸了可播放的内容项目,它们就需要显示正在播放的信息中心 (2) 并响应播放按钮 (1)。您应该设置正在播放的信息键以响应委托方法 playableContentManager:initiatePlaybackOfContentItemAtIndexPath:completionHandler。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-07
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多