doorxp

Blog

Carplay NSIndexPath 对应关系.

@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


发表评论:

«   2024年11月   »
123
45678910
11121314151617
18192021222324
252627282930
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言

    Powered By Z-BlogPHP 1.5.1 Zero

    Copyright doorxp.com Rights Reserved.