Hi!
A few weeks ago I finally updated my audio app to support CarPlay. I have tested it with the 12.4 simulator and it was running fine. Now, if I compile and test on the iOS 13.1 simulator, it tells me that CarPlay can't connect to my app. The same happens if my colleague tries to use the app in a real CarPlay environment. A few days ago he also updated his XR to iOS 13.1, so we can't test it with a real iOS 12.4.
I don't understand what I could be missing. I already searched on StackOverflow and googled lots of possible keywords. But I've found nothing that would help or give a hint what's wrong with my app.
Again, all is fine with iOS 12.4 simulator.
If someone has an idea or advice, what could cause my problems, please feel free to post an answer.
Here is a short overview (essential methods only), what I've implemented:
@implementation CPMainController
- (instancetype)init {
self = [super init];
if (self) {
DLog(@"I", @"");
// 1. code that registers handlers with the MPRemoteCommandCenter:
// playCommand,
// pauseCommand,
// stopCommand,
// togglePlayPauseCommand,
// previousTrackCommand and
// nextTrackCommand
// 2. code that invokes '[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = someTitleInfo;'
_playableContentManager = [MPPlayableContentManager.sharedContentManager retain];
_playableContentManager.dataSource = self.dataSource;
_playableContentManager.delegate = self.delegate;
/* here, I already tried several variants and combinations */
// [_playableContentManager beginUpdates];
// DLog(@"I", @"force load the content items");
// [self.dataSource contentItems];
// [_playableContentManager endUpdates];
[_playableContentManager reloadData];
}
}
- (cp_data_source*)dataSource {
// lazy getter, creates and returns an instance of 'cp_data_source'
}
- (cp_delegate*)delegate {
// lazy getter, creates and returns an instance of 'cp_delegate'
}
(... some other stuff for memory management ...)
@end
@implementation cp_data_source
- (NSArray<mpcontentitem*>*)contentItems {
// lazy getter, creates and returns the MPContentItem objects
}
- (void)beginLoadingChildItemsAtIndexPath:(NSIndexPath*)indexPath
completionHandler:(void (^)(NSError* __nullable))completionHandler {
// protocol method, never gets called on ios 13
}
- (BOOL)childItemsDisplayPlaybackProgressAtIndexPath:(NSIndexPath*)indexPath {
// implemented
}
- (void)contentItemForIdentifier:(NSString*)identifier
completionHandler:(void (^)(MPContentItem* _Nullable, NSError* _Nullable))completionHandler {
// implemented
}
- (NSInteger)numberOfChildItemsAtIndexPath:(NSIndexPath*)indexPath {
// implemented
}
- (MPContentItem*)contentItemAtIndexPath:(NSIndexPath*)indexPath {
// implemented
}
@end
@implementation cp_delegate
- (void)playableContentManager:(MPPlayableContentManager*)contentManager
initiatePlaybackOfContentItemAtIndexPath:(NSIndexPath*)indexPath
completionHandler:(void (^)(NSError* __nullable))completionHandler {
// implemented, plus the following snippet:
#if (TARGET_IPHONE_SIMULATOR)
[UIApplication.sharedApplication endReceivingRemoteControlEvents];
[UIApplication.sharedApplication beginReceivingRemoteControlEvents];
#endif
}
@end
For completeness, my logs with the two simulators...
--- For iOS 12.4: ---
[I] -[CPMainController init]:
[I] NowPlaying:
{
artist = "CPMainController";
artwork = "<MPMediaItemArtwork: 0x600000510140>";
title = Stopped;
}
[I] -[CPMainController dataSource]:
[I] -[cp_data_source init]:
[I] -[CPMainController delegate]:
[I] -[cp_delegate init]:
...(
now I open the car play external display in simulator:
* the phone screen dims and shows that car play is active now.
)...
[I] -[cp_data_source beginLoadingChildItemsAtIndexPath:completionHandler:]:
[I] -[cp_data_source setRadioStations:]:
[I] -[cp_data_source childItemsDisplayPlaybackProgressAtIndexPath:]:
[I] -[cp_data_source numberOfChildItemsAtIndexPath:]:
[I] -[cp_data_source contentItemAtIndexPath:]:
[I] -[cp_data_source tabItems]:
--- For iOS 13: ---
[I] -[CPMainController init]:
[I] NowPlaying:
{
artist = "CPMainController";
artwork = "<MPMediaItemArtwork: 0x600002bb3160>";
title = Stopped;
}
[I] -[CPMainController dataSource]:
[I] -[cp_data_source init]:
[I] -[CPMainController delegate]:
[I] -[cp_delegate init]:
...(
now I open the car play external display in simulator:
* the phone screen gets black (showing an activity indicator)
for a second and then again shows my app's main screen
* nothing else happens
)...
Thank you in advance!