Skip to content

Commit 2585a90

Browse files
committed
update demo
1 parent 7607e57 commit 2585a90

File tree

15 files changed

+541
-24
lines changed

15 files changed

+541
-24
lines changed

Example/VPInterfaceControllerDemo.xcodeproj/project.pbxproj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
C42CDB951F33289F00DD42D0 /* PrivateConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = C42CDB941F33289F00DD42D0 /* PrivateConfig.m */; };
2727
C4BB02A51F8F426100CC195C /* VPMediaMoreButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BB02A41F8F426100CC195C /* VPMediaMoreButtonView.m */; };
2828
C4BB02A71F8F427600CC195C /* VPMediaMoreButtonView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C4BB02A61F8F427600CC195C /* VPMediaMoreButtonView.xib */; };
29+
D00D67AD22D42FD60003972F /* VPConfigData.m in Sources */ = {isa = PBXBuildFile; fileRef = D00D67A622D42FD60003972F /* VPConfigData.m */; };
30+
D00D67AE22D42FD60003972F /* VPConfigListData.m in Sources */ = {isa = PBXBuildFile; fileRef = D00D67A922D42FD60003972F /* VPConfigListData.m */; };
31+
D00D67AF22D42FD60003972F /* VPModel+DictionaryToModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D00D67AA22D42FD60003972F /* VPModel+DictionaryToModel.m */; };
32+
D00D67B022D42FD60003972F /* VPModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D00D67AC22D42FD60003972F /* VPModel.m */; };
2933
D0102BBF214F7A85003C11A0 /* adInfo.json in Resources */ = {isa = PBXBuildFile; fileRef = D0102BBE214F7A85003C11A0 /* adInfo.json */; };
3034
D022A0DC20C688C900F46029 /* VPLiveSelectStatusViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D022A0D820C688C900F46029 /* VPLiveSelectStatusViewController.m */; };
3135
D022A0DD20C688C900F46029 /* VPLiveTypeSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D022A0DB20C688C900F46029 /* VPLiveTypeSelectViewController.m */; };
@@ -70,6 +74,14 @@
7074
C4BB02A31F8F426100CC195C /* VPMediaMoreButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPMediaMoreButtonView.h; sourceTree = "<group>"; };
7175
C4BB02A41F8F426100CC195C /* VPMediaMoreButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPMediaMoreButtonView.m; sourceTree = "<group>"; };
7276
C4BB02A61F8F427600CC195C /* VPMediaMoreButtonView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VPMediaMoreButtonView.xib; sourceTree = "<group>"; };
77+
D00D67A522D42FD60003972F /* VPModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPModel.h; sourceTree = "<group>"; };
78+
D00D67A622D42FD60003972F /* VPConfigData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPConfigData.m; sourceTree = "<group>"; };
79+
D00D67A722D42FD60003972F /* VPModel+DictionaryToModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "VPModel+DictionaryToModel.h"; sourceTree = "<group>"; };
80+
D00D67A822D42FD60003972F /* VPConfigListData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPConfigListData.h; sourceTree = "<group>"; };
81+
D00D67A922D42FD60003972F /* VPConfigListData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPConfigListData.m; sourceTree = "<group>"; };
82+
D00D67AA22D42FD60003972F /* VPModel+DictionaryToModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "VPModel+DictionaryToModel.m"; sourceTree = "<group>"; };
83+
D00D67AB22D42FD60003972F /* VPConfigData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPConfigData.h; sourceTree = "<group>"; };
84+
D00D67AC22D42FD60003972F /* VPModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPModel.m; sourceTree = "<group>"; };
7385
D0102BBE214F7A85003C11A0 /* adInfo.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = adInfo.json; sourceTree = "<group>"; };
7486
D022A0D820C688C900F46029 /* VPLiveSelectStatusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPLiveSelectStatusViewController.m; sourceTree = "<group>"; };
7587
D022A0D920C688C900F46029 /* VPLiveSelectStatusViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPLiveSelectStatusViewController.h; sourceTree = "<group>"; };
@@ -147,6 +159,7 @@
147159
069D54371F04DC6D001E5324 /* VPInterfaceControllerDemo */ = {
148160
isa = PBXGroup;
149161
children = (
162+
D00D67A422D42FD60003972F /* Model */,
150163
D0C76AC42283C93C00C4791F /* VPVideoAppSettingView.h */,
151164
D0C76AC32283C93C00C4791F /* VPVideoAppSettingView.m */,
152165
D0DA384421A7E2F20014A855 /* VPLoginViewController.h */,
@@ -202,6 +215,21 @@
202215
name = Pods;
203216
sourceTree = "<group>";
204217
};
218+
D00D67A422D42FD60003972F /* Model */ = {
219+
isa = PBXGroup;
220+
children = (
221+
D00D67A522D42FD60003972F /* VPModel.h */,
222+
D00D67A622D42FD60003972F /* VPConfigData.m */,
223+
D00D67A722D42FD60003972F /* VPModel+DictionaryToModel.h */,
224+
D00D67A822D42FD60003972F /* VPConfigListData.h */,
225+
D00D67A922D42FD60003972F /* VPConfigListData.m */,
226+
D00D67AA22D42FD60003972F /* VPModel+DictionaryToModel.m */,
227+
D00D67AB22D42FD60003972F /* VPConfigData.h */,
228+
D00D67AC22D42FD60003972F /* VPModel.m */,
229+
);
230+
path = Model;
231+
sourceTree = "<group>";
232+
};
205233
D078CD76214A04BD008946CC /* Resources */ = {
206234
isa = PBXGroup;
207235
children = (
@@ -366,9 +394,11 @@
366394
068965351F14EDA60054736C /* VPAVPlayerController.m in Sources */,
367395
069D54401F04DC6D001E5324 /* ViewController.m in Sources */,
368396
D078CD7B214A054D008946CC /* VPWebViewController.m in Sources */,
397+
D00D67B022D42FD60003972F /* VPModel.m in Sources */,
369398
C4BB02A51F8F426100CC195C /* VPMediaMoreButtonView.m in Sources */,
370399
D0DA384621A7E2F20014A855 /* VPLoginViewController.m in Sources */,
371400
D022A0DC20C688C900F46029 /* VPLiveSelectStatusViewController.m in Sources */,
401+
D00D67AE22D42FD60003972F /* VPConfigListData.m in Sources */,
372402
069D543D1F04DC6D001E5324 /* AppDelegate.m in Sources */,
373403
D022A0E020C6932B00F46029 /* VPVideoSettingView.m in Sources */,
374404
0689653C1F15F2BB0054736C /* VPMediaControlView.m in Sources */,
@@ -378,6 +408,8 @@
378408
C42CDB951F33289F00DD42D0 /* PrivateConfig.m in Sources */,
379409
069D543A1F04DC6D001E5324 /* main.m in Sources */,
380410
068965411F1607180054736C /* VPSinglePlayerViewController.m in Sources */,
411+
D00D67AF22D42FD60003972F /* VPModel+DictionaryToModel.m in Sources */,
412+
D00D67AD22D42FD60003972F /* VPConfigData.m in Sources */,
381413
);
382414
runOnlyForDeploymentPostprocessing = 0;
383415
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// VPConfigData.h
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "VPModel.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface VPConfigData : VPModel
15+
16+
@property (nonatomic) NSString *appKey;
17+
@property (nonatomic) NSString *appSecret;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// VPConfigData.m
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import "VPConfigData.h"
10+
11+
@implementation VPConfigData
12+
13+
@end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// VPConfigListData.h
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "VPConfigData.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface VPConfigListData : NSObject
15+
16+
+ (VPConfigListData *)shared;
17+
18+
@property (nonatomic, readonly) NSMutableArray<VPConfigData *> *data;
19+
@property (nonatomic, assign) NSInteger selectedIndex;
20+
21+
- (NSArray *)appKeyArray;
22+
- (NSArray *)appSecretArray;
23+
24+
- (void)addConfigData:(VPConfigData *)configData;
25+
26+
@end
27+
28+
NS_ASSUME_NONNULL_END
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// VPConfigListData.m
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import "VPConfigListData.h"
10+
#import "VPModel+DictionaryToModel.h"
11+
12+
static VPConfigListData *shared = nil;
13+
14+
@implementation VPConfigListData
15+
16+
+ (VPConfigListData *)shared {
17+
static dispatch_once_t onceToken;
18+
dispatch_once(&onceToken, ^{
19+
shared = [[self alloc] init];
20+
});
21+
return shared;
22+
}
23+
24+
- (instancetype)init {
25+
self = [super init];
26+
if (self != nil) {
27+
_selectedIndex = -1;
28+
[self initData];
29+
}
30+
31+
return self;
32+
}
33+
34+
- (void)initData {
35+
if (_data == nil) {
36+
_data = [NSMutableArray array];
37+
NSString *dataPath = [VPConfigListData configPath];
38+
NSArray *dataArray = [NSArray arrayWithContentsOfFile:dataPath];
39+
if (dataArray != nil) {
40+
_data = [NSMutableArray array];
41+
for (NSDictionary *dict in dataArray) {
42+
VPConfigData *configData = [VPConfigData modelWithDictionary:dict];
43+
if (configData != nil) {
44+
[_data addObject:configData];
45+
}
46+
}
47+
}
48+
}
49+
}
50+
51+
- (void)addConfigData:(VPConfigData *)configData {
52+
if (configData.appKey != nil && configData.appSecret != nil) {
53+
NSInteger appKeyPosition = -1;
54+
NSInteger appSecretPosition = -1;
55+
for (VPConfigData *config in _data) {
56+
if ([config.appKey isEqualToString:configData.appKey]) {
57+
appKeyPosition = [_data indexOfObject:config];
58+
}
59+
if ([config.appSecret isEqualToString:configData.appSecret]) {
60+
appSecretPosition = [_data indexOfObject:config];
61+
}
62+
}
63+
64+
if (appKeyPosition != -1 && appKeyPosition == appSecretPosition) {
65+
return;
66+
}
67+
68+
[_data addObject:configData];
69+
70+
NSMutableArray *writeArray = [NSMutableArray array];
71+
for (VPConfigData *config in _data) {
72+
NSDictionary *dict = [config modelToDictionary];
73+
[writeArray addObject:dict];
74+
}
75+
76+
[writeArray writeToFile:[VPConfigListData configPath] atomically:YES];
77+
}
78+
}
79+
80+
+ (NSString *)configPath {
81+
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
82+
83+
path = [path stringByAppendingPathComponent:@"config.plist"];
84+
return path;
85+
}
86+
87+
- (NSArray *)appKeyArray {
88+
NSMutableArray *array = [NSMutableArray array];
89+
for (VPConfigData *config in _data) {
90+
[array addObject:config.appKey];
91+
}
92+
93+
return array;
94+
}
95+
96+
- (NSArray *)appSecretArray {
97+
NSMutableArray *array = [NSMutableArray array];
98+
for (VPConfigData *config in _data) {
99+
[array addObject:config.appSecret];
100+
}
101+
102+
return array;
103+
}
104+
105+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// VPModel+DictionaryToModel.h
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import "VPModel.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface VPModel (DictionaryToModel)
14+
15+
+ (instancetype)modelWithDictionary:(NSDictionary *)dict;
16+
17+
- (NSDictionary *)modelToDictionary;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// VPModel+DictionaryToModel.m
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import "VPModel+DictionaryToModel.h"
10+
#import <objc/message.h>
11+
12+
@implementation VPModel (DictionaryToModel)
13+
14+
+ (instancetype)modelWithDictionary:(NSDictionary *)dict {
15+
if (![dict isKindOfClass:[NSDictionary class]]) {
16+
return nil;
17+
}
18+
//1. 创建对应的对象
19+
id model = [[self alloc] init];
20+
21+
unsigned int count = 0;
22+
Ivar *ivarList = class_copyIvarList(self, &count);
23+
24+
for (int i = 0; i < count; i++) {
25+
Ivar ivar = ivarList[i];
26+
// 获取成员变量名字
27+
NSString *ivarName = [NSString stringWithUTF8String:ivar_getName(ivar)];
28+
29+
// 处理成员变量名->字典中的key(去掉 _ ,从第一个角标开始截取)
30+
NSString *key = [ivarName substringFromIndex:1];
31+
32+
// 根据成员属性名去字典中查找对应的value
33+
id value = dict[key];
34+
35+
if (value) {
36+
[model setValue:value forKey:key];
37+
}
38+
}
39+
40+
return model;
41+
}
42+
43+
- (NSDictionary *)modelToDictionary {
44+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
45+
46+
unsigned int count = 0;
47+
Ivar *ivarList = class_copyIvarList([self class], &count);
48+
49+
for (int i = 0; i < count; i++) {
50+
Ivar ivar = ivarList[i];
51+
// 获取成员变量名字
52+
NSString *ivarName = [NSString stringWithUTF8String:ivar_getName(ivar)];
53+
54+
// 处理成员变量名->字典中的key(去掉 _ ,从第一个角标开始截取)
55+
NSString *key = [ivarName substringFromIndex:1];
56+
57+
// 根据成员属性名去字典中查找对应的value
58+
id value = [self valueForKey:key];
59+
60+
if (value) {
61+
[dict setValue:value forKey:key];
62+
}
63+
}
64+
65+
return dict;
66+
}
67+
68+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// VPModel.h
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface VPModel : NSObject
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// VPModel.m
3+
// VideoOSDemo
4+
//
5+
// Created by Zard1096-videojj on 2019/2/26.
6+
// Copyright © 2019 videopls. All rights reserved.
7+
//
8+
9+
#import "VPModel.h"
10+
11+
@implementation VPModel
12+
13+
@end

0 commit comments

Comments
 (0)