本文介绍了MPPlayableContentDataSource调用不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I am working on implementing support for a CarPlay audio app, and am attempting to display listings in the simulator. I have implemented MPPlayableContentDataSource, but find that it is called inconsistently. It is called the first time the app is launched on a simulator, and if CarPlay is open on launch, I can make the first item display by scrolling up an otherwise empty listing to trigger a redraw. CarPlay does not seem able to call the data source, however, and on a subsequent launch I see an empty screen or a spinner followed by the message Unable to connect to "AppName". I have tried different things but the main points are as follows:

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方法,但是这些都不导致内容数据源实际被调用.

I've played around with beginUpdates endUpdates and reloadData methods of the content manager, but none of these result in the content datasource actually being called.

我已经在数据源中实现了numberOfChildItemsAtIndexPathcontentItemAtIndexPath,尽管只有在全新模拟器上首次启动该应用程序时,它们才能被正确调用.

I've implemented numberOfChildItemsAtIndexPath and contentItemAtIndexPath in the datasource, which appear to be called correctly, although only on the first launch of the app on a fresh simulator.

要点:

- (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的引用.

I've also tried retaining (or not) the reference to the MPPlayableContentManager.

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

I have the same behavior on an actual head unit. Any help would be appreciated.

推荐答案

我的头撞墙了好一会儿之后,我从苹果公司得到了以下答案.事实证明,要运行CarPlay,需要MPRemoteCommandCenterMPNowPlayingInfoCenter.

After banging my head against the wall for quite a while, I got the following answer from Apple. Turns out that MPRemoteCommandCenter and MPNowPlayingInfoCenter are needed for CarPlay to work.

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.

文档中提到了它们,但尚不清楚它们是否需要目录显示才能正常工作.那解决了问题.

They are mentioned in the doc, but it isn't clear that they are needed for the catalog display to work. That solved the problem.

这篇关于MPPlayableContentDataSource调用不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:21