CNTools.m 2.5 KB
//
//  CNTools.m
//  CNLiveNetAdd
//
//  Created by 张旭 on 2017/12/30.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import "CNTools.h"
#import <CNLiveEnvironment/CNLiveEnvironment.h>
#import <MJExtension.h>
#import <CNLiveRequestBastKit/CNLiveNetworking.h>
#import <CNLiveBaseKit/CNLiveBaseKit.h>
#import <NSString+CNLiveExtension.h>
#import <CNUserInfoManager.h>
#import <CNLiveCommonCategory/CNLiveCommonCategory.h>
#import <CNLiveVideoClassifyKit/CNLivevideoClassifyPCH.h>
#import <CNLiveBeeHive/BHConfig.h>


static NSString * const CNDarenDownloadShareSourceUrl = @"CNDarenDownloadShareSourceUrl";
//24*60*60*1000
#define kTimerLength 24*60*60*1000

@interface CNTools ()

@property (nonatomic, assign) BOOL firstDownload;
@property (nonatomic, assign) BOOL needToChange;
@property (nonatomic, copy) NSString *channel;

@end

@implementation CNTools

+ (instancetype)manager {
    static CNTools *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc] init];
    });
    return manager;
}
+ (void)GetClassifyChannelsUrlsAndSave {
    
    if ([CNTools manager].channelsRequesting) {
        return;
    }
    [CNTools manager].channelsRequesting = YES;
    NSDictionary *dic = @{
        @"plat":@"i"
    };
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCategoryGetChannelUrl Param:dic CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        NSMutableArray *jsonArray = [[NSMutableArray alloc] init];
        if ([NSArray isArray:responseObject[@"data"]]) {
            
            for (NSDictionary *dic in responseObject[@"data"]) {
                NSString *jsonStr = CNLiveNSDictionaryDicToJson(dic);
                [jsonArray addObject:jsonStr];
            }
            [[NSUserDefaults standardUserDefaults] setObject:jsonArray forKey:CNLiveNetAddGetCategoryChannels];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        if (![NSArray isArray:jsonArray]) {
            [[NSNotificationCenter defaultCenter] postNotificationName:CNWjjClassifyChannelsRequestStateNotifiName object:nil userInfo:@{@"success":@"1"}];
        } else {
            [[NSNotificationCenter defaultCenter] postNotificationName:CNWjjClassifyChannelsRequestHideLoadingNotifiName object:nil userInfo:nil];
        }
        [CNTools manager].channelsRequesting = NO;
        [BHConfig set:ChannelsRequested boolValue:YES];
    }];
    
}




@end