GromoreDemoDeviceInfoView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // GromoreDemoDeviceInfoView.m
  3. // ABUDemo
  4. //
  5. // Created by bytedance on 2022/2/15.
  6. // Copyright © 2022 bytedance. All rights reserved.
  7. //
  8. #import "GromoreDemoDeviceInfoView.h"
  9. #import <AdSupport/AdSupport.h>
  10. /// 可视化测试工具
  11. //#import <ABUVisualDebug/ABUVisualDebug.h>
  12. @interface GromoreDemoDeviceInfoView () <UITableViewDelegate, UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) UIView *contentView;
  15. @property (nonatomic, strong) UIButton *closeButton;
  16. @property (nonatomic, copy) NSArray *list;
  17. @end
  18. @implementation GromoreDemoDeviceInfoView
  19. + (void)show {
  20. CGRect frame = [UIScreen mainScreen].bounds;
  21. GromoreDemoDeviceInfoView *view = [[GromoreDemoDeviceInfoView alloc] initWithFrame:frame];
  22. [[self mainWindow] addSubview:view];
  23. }
  24. - (instancetype)initWithFrame:(CGRect)frame {
  25. if (self = [super initWithFrame:frame]) {
  26. [self setupData];
  27. [self setupView];
  28. }
  29. return self;
  30. }
  31. - (void)setupView {
  32. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
  33. CGFloat width = self.frame.size.width * 0.8f;
  34. CGRect frame = CGRectMake(0, 0, width, width);
  35. self.contentView = [[UIView alloc] initWithFrame:frame];
  36. self.contentView.center = CGPointMake(self.frame.size.width * .5f, self.frame.size.height * 0.4f);
  37. self.contentView.backgroundColor = [UIColor whiteColor];
  38. self.contentView.layer.cornerRadius = 4.f;
  39. self.contentView.clipsToBounds = YES;
  40. [self addSubview:self.contentView];
  41. CGRect tvFrame = CGRectMake(0, 20, width, width - 20);
  42. self.tableView = [[UITableView alloc] initWithFrame:tvFrame];
  43. self.tableView.delegate = self;
  44. self.tableView.dataSource = self;
  45. self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
  46. [self.contentView addSubview:self.tableView];
  47. self.closeButton = [[UIButton alloc] init];
  48. [self.closeButton setTitle:@" X " forState:UIControlStateNormal];
  49. [self.closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  50. self.closeButton.titleLabel.font = RQRegularFont(12);
  51. [self.closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  52. [self.contentView addSubview:self.closeButton];
  53. [self.closeButton sizeToFit];
  54. self.closeButton.frame = CGRectOffset(self.closeButton.frame, width - self.closeButton.frame.size.width - 5.f, 5.f);
  55. }
  56. - (void)setupData {
  57. NSMutableArray *list = [NSMutableArray array];
  58. [list addObject:@{
  59. @"title" : @"GroMore",
  60. @"value" : [NSClassFromString(@"ABUAdSDKManager") performSelector:NSSelectorFromString(@"SDKVersion")],
  61. }];
  62. [list addObject:@{
  63. @"title" : @"IDFA",
  64. @"value" : [self get_idfa],
  65. }];
  66. [list addObject:@{
  67. @"title" : @"IDFV",
  68. @"value" : [self get_idfv],
  69. }];
  70. [list addObject:@{
  71. @"title" : @"测试工具入口"
  72. }];
  73. self.list = list.copy;
  74. }
  75. - (NSString *)get_idfv {
  76. return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
  77. }
  78. - (NSString *)get_idfa {
  79. NSString *version = [UIDevice currentDevice].systemVersion;
  80. if (version.doubleValue >= 14.0) {
  81. if ([ASIdentifierManager.sharedManager isAdvertisingTrackingEnabled]) {
  82. return [ASIdentifierManager.sharedManager advertisingIdentifier].UUIDString;
  83. } else {
  84. return nil;
  85. }
  86. } else {
  87. return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  88. }
  89. }
  90. - (void)closeAction {
  91. [self removeFromSuperview];
  92. }
  93. + (UIWindow *)mainWindow {
  94. UIWindow *window = nil;
  95. if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) {
  96. window = [[UIApplication sharedApplication].delegate window];
  97. }
  98. if (![window isKindOfClass:[UIView class]]) {
  99. window = [UIApplication sharedApplication].keyWindow;
  100. }
  101. if (!window) {
  102. window = [[UIApplication sharedApplication].windows objectAtIndex:0];
  103. }
  104. return window;
  105. }
  106. #pragma mark - UITableViewDelegate, UITableViewDataSource
  107. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  108. return self.list.count;
  109. }
  110. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  111. NSDictionary *dict = self.list[indexPath.row];
  112. NSString *title = dict[@"title"];
  113. NSString *value = dict[@"value"];
  114. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  115. if (!cell) {
  116. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  117. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  118. }
  119. cell.textLabel.text = title;
  120. cell.detailTextLabel.text = value;
  121. return cell;
  122. }
  123. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  124. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  125. if (indexPath.row == 3) {
  126. /// 开启可视化测试工具
  127. [self startTestTool];
  128. return;
  129. }
  130. NSDictionary *dict = self.list[indexPath.row];
  131. NSString *title = dict[@"title"];
  132. NSString *value = dict[@"value"];
  133. [[UIPasteboard generalPasteboard] setString:value];
  134. Class cls = NSClassFromString(@"ABUToastView");
  135. if ([cls respondsToSelector:@selector(showWithTitle:)]) {
  136. [cls performSelector:@selector(showWithTitle:) withObject:[title stringByAppendingString:@"已复制"]];
  137. }
  138. }
  139. #pragma mark 开启可视化测试工具
  140. - (void)startTestTool {
  141. // BOOL result = [ABUVisualDebug startVisualDebug];
  142. // if (!result) {
  143. // NSLog(@"可视化工具初始化失败,请检查配置 ~ ");
  144. // }
  145. }
  146. @end