@implementation AppDelegate(Carplay)
- (void)registerCarPlay {
MPPlayableContentManager.sharedContentManager.delegate = self;
MPPlayableContentManager.sharedContentManager.dataSource = self;
}
- (void)beginLoadingChildItemsAtIndexPath:(NSIndexPath *)indexPath completionHandler:(void(^)(NSError * __nullable))completionHandler {
completionHandler(nil);
}
- (BOOL)childItemsDisplayPlaybackProgressAtIndexPath:(NSIndexPath *)indexPath {
return false;
}
- (void)contentItemForIdentifier:(NSString *)identifier completionHandler:(void(^)(MPContentItem *__nullable, NSError * __nullable))completionHandler MP_API(ios(10.0)) MP_PROHIBITED(tvos, macos, watchos) {
// completionHandler()
}
- (NSInteger)numberOfChildItemsAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.length == 0) {
return 3;
}
else if(indexPath.length == 1) {
switch (indexPath.section) {
case 0:
return 1;
break;
case 1:
return 2;
break;
default:
return 3;
break;
}
}
else {
return 3;
}
}
- (nullable MPContentItem *)contentItemAtIndexPath:(NSIndexPath *)indexPath {
MPContentItem *item = nil;
if (indexPath.length == 1) {
NSString *ident = [@"T" stringByAppendingString:@(indexPath.section).stringValue];
item = [[MPContentItem alloc] initWithIdentifier:ident];
item.title = ident;
}
else if(indexPath.length == 2){
NSString *ident = [NSString stringWithFormat:@"C-%ld-%ld", (long)indexPath.section, (long)indexPath.row];
item = [[MPContentItem alloc] initWithIdentifier:ident];
item.title = ident;
}
else {
NSString *ident = [NSString stringWithFormat:@"C-%ld", indexPath.section];
for (int i = 1; i<indexPath.length; i++) {
ident = [ident stringByAppendingFormat:@"-%ld", [indexPath indexAtPosition:i]];
}
item = [[MPContentItem alloc] initWithIdentifier:ident];
item.title = ident;
}
item.playable = false;
item.container = true;
return item;
}
@end