1

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:

In 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];

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.

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.

The main points:

- (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;
}

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.

Tad
  • 4,668
  • 34
  • 35
  • Please file a bug report at https://bugreport.apple.com. Attach your project (or a sample project). Reproduce the problem and while the Simulator is still booted run `xcrun simctl diagnose` then attach the output to the bug report. – russbishop Sep 14 '17 at 19:58
  • Thanks for the note - I was able to reproduce the behavior on an actual head unit, so it isn't a simulator bug - presumably a bug in my code somewhere. I will try to build a sample project to confirm, and file a bug if it doesn't repro. Working on another project right now, but should get back to this shortly. – Tad Sep 22 '17 at 12:12
  • I'd be interested in talking if you still need help, I have experience with CarPlay. Please reach out. – Billy Caruso Dec 12 '17 at 20:43

1 Answers1

2

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.

Tad
  • 4,668
  • 34
  • 35
  • Steps 1 and 2 are not needed to display the content items on screen. Once you touch a playable content item they are needed to display the now playing info center (2) and to respond to the playback buttons (1). You should set the now playing info keys in response to the delegate method playableContentManager:initiatePlaybackOfContentItemAtIndexPath:completionHandler. – Patrick Bodet Jan 19 '19 at 10:23