CNLIVEViewController.m 4.59 KB
//
//  CNLIVEViewController.m
//  CNLiveBBASMModule
//
//  Created by 杨苓玉 on 10/21/2021.
//  Copyright (c) 2021 杨苓玉. All rights reserved.
//

#import "CNLIVEViewController.h"
#import "CNLiveBBASMModule/CNLiveBBASMModuleService.h"
#import <CNLiveBeeHive/CNLiveBeeHive.h>
#import <CNLiveBusinessTools/CNLiveEscpTools.h>
#import <CNLiveBaseKit/CNLiveBaseKit.h>

@interface CNLIVEViewController ()<HomeServiceProtocol>

@end

@BeeHiveService(HomeServiceProtocol, CNLIVEViewController)
@implementation CNLIVEViewController
- (UIViewController *)getConnnectVC
{
    CNLIVEViewController *vc = [[CNLIVEViewController alloc] init];
    return vc;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSArray *titleArray = [NSArray arrayWithObjects:@"百度小程序",@"退出登录",@"分享链接打开",@"猫眼视频",@"e代驾",@"高铁",@"英语学习", nil];
    for (int i = 0;i < titleArray.count;i++){
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 40+100 + 54 *i, [UIScreen mainScreen].bounds.size.width, 44)];
        btn.tag = 1001 + i;
        [btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitle:titleArray[i] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor grayColor];
        [self.view addSubview:btn];
    }
    
}
-(void)action:(UIButton *)sender
{
    switch (sender.tag - 1001) {
        case 0:
        {
            NSString *spURL = @"cnlive://swan/4fecoAqgCIUtzIyA4FAPgoyrc4oUc25c";
            [CNLiveBBASMModuleService openBBASMModule:spURL];
        }
            break;
        case 1:
        {
            [CNLiveBBASMModuleService accountLogout];
        }
            break;
        case 2:
        {
            NSString *urlStr = @"";
            NSURL *url = [NSURL URLWithString:urlStr];
            NSDictionary * paramDic = [self requestURLParameters:url];
            [CNLiveBBASMModuleService openBBASMModule:[NSString stringWithFormat:@"cnlive://swan/%@",[CNLiveEscpTools unesp:paramDic[@"swanId"]]]];
        }
            break;
        case 3:
        {
            NSString *spURL = @"cnlive://swan/WtZRSkMo3I3VcIQ3unY30Ch4y9Wxr0nN";
            [CNLiveBBASMModuleService openBBASMModule:spURL];
        }
            break;
        case 4:
        {
            NSString *spURL = @"cnlive://swan/FdMouSDlO3kyhUoMz0wtlnukEkfHKxDI";
            [CNLiveBBASMModuleService openBBASMModule:spURL];
        }
            break;
        case 5:
        {
            NSString *spURL = @"cnlive://swan/fn4HbXgoHtGWc1TkREts2nDTZKE0wvIh";
            [CNLiveBBASMModuleService openBBASMModule:spURL];
        }
            break;
        case 6:
        {
            NSString *spURL = @"cnlive://swan/lDvbSAZzaa8xPTQ8M0EquG1xos75HGvU";
            [CNLiveBBASMModuleService openBBASMModule:spURL];
        }
            break;
            
        default:
            break;
    }
    
}
//参数的跳转逻辑
-(NSDictionary *)requestURLParameters:(NSURL *)urlStr
{
    NSMutableDictionary *parm = [[NSMutableDictionary alloc]init];
    
    //回调遍历所有参数,添加入字典
    if (@available(iOS 11.0, *)) {
        //传入url创建url组件类
        NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithString:urlStr.absoluteString];
        [urlComponents.percentEncodedQueryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (!CNLiveStringIsEmpty(obj.name) && !CNLiveStringIsEmpty(obj.value)) {
                if ([obj.name isEqualToString:@"//type"]) {
                    [parm setObject:obj.value forKey:@"type"];
                }else{
                    [parm setObject:obj.value forKey:obj.name];
                }
            }
        }];
    } else {
        // Fallback on earlier versions
        NSString * path = [urlStr.absoluteString componentsSeparatedByString:@"?"].lastObject;
        NSArray * paramArray = [path componentsSeparatedByString:@"&"];
        [paramArray enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSArray * tempArray = [obj componentsSeparatedByString:@"="];
            if ([tempArray.firstObject isEqualToString:@"//type"]) {
                [parm setObject:tempArray.lastObject forKey:@"type"];
            }else{
                [parm setObject:tempArray.lastObject forKey:tempArray.firstObject];
            }
        }];
    }
    
    return parm;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end