CNTools.m
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// 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