|
| 1 | +// |
| 2 | +// TIoTAreaNetworkConfigVC.m |
| 3 | +// LinkSDKDemo |
| 4 | + |
| 5 | +#import "TIoTDeviceInfoVC.h" |
| 6 | +#import "TIoTDemoPreviewDeviceVC.h" |
| 7 | +#import "TIoTAreaNetworkDeviceCell.h" |
| 8 | +#import "TIoTLocalNetDetch.h" |
| 9 | +#import "TIoTCoreAppEnvironment.h" |
| 10 | +#import "TIoTCoreUserManage.h" |
| 11 | +#import "NSString+Extension.h" |
| 12 | +#import "UIImage+TIoTDemoExtension.h" |
| 13 | + |
| 14 | +@interface TIoTDeviceInfoVC ()<UITextFieldDelegate> |
| 15 | +@property (nonatomic, strong) UITextField *productID; |
| 16 | +@property (nonatomic, strong) UITextField *devicenname; |
| 17 | +@property (nonatomic, strong) UITextField *xp2pinfo; |
| 18 | +@end |
| 19 | + |
| 20 | +@implementation TIoTDeviceInfoVC |
| 21 | + |
| 22 | +- (void)viewDidLoad { |
| 23 | + [super viewDidLoad]; |
| 24 | + // Do any additional setup after loading the view. |
| 25 | + [self setupUI]; |
| 26 | + |
| 27 | + [self setupNavBarStyleWithNormal:NO]; |
| 28 | + if (@available(iOS 13.0, *)) { |
| 29 | + UINavigationBarAppearance *barApp = [[UINavigationBarAppearance alloc] init]; |
| 30 | + [barApp configureWithOpaqueBackground]; |
| 31 | + barApp.backgroundColor = [UIColor whiteColor]; |
| 32 | + barApp.shadowColor = [UIColor clearColor]; |
| 33 | + barApp.shadowImage = [UIImage new]; |
| 34 | + self.navigationController.navigationBar.standardAppearance = barApp; |
| 35 | + self.navigationController.navigationBar.scrollEdgeAppearance = barApp; |
| 36 | + } |
| 37 | +} |
| 38 | +- (void)viewWillAppear:(BOOL)animated { |
| 39 | + [super viewWillAppear:animated]; |
| 40 | + [self setupNavBarStyleWithNormal:NO]; |
| 41 | +} |
| 42 | + |
| 43 | +- (void)viewWillDisappear:(BOOL)animated { |
| 44 | + [super viewWillDisappear:animated]; |
| 45 | + [self setupNavBarStyleWithNormal:YES]; |
| 46 | +} |
| 47 | + |
| 48 | +- (void)setupNavBarStyleWithNormal:(BOOL)isNormal { |
| 49 | + |
| 50 | + if (isNormal) { |
| 51 | + [self.navigationController.navigationBar setBackgroundImage:[UIImage getGradientImageWithColors:@[[UIColor colorWithHexString:@"#ffffff"],[UIColor colorWithHexString:@"#ffffff"]] imgSize:CGSizeMake(kScreenWidth, 44)] forBarMetrics:UIBarMetricsDefault]; |
| 52 | + }else { |
| 53 | + [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FFFFFF"],NSFontAttributeName:[UIFont wcPfRegularFontOfSize:17]}]; |
| 54 | + [self.navigationController.navigationBar setBackgroundImage:[UIImage getGradientImageWithColors:@[[UIColor colorWithHexString:@"#3D8BFF"],[UIColor colorWithHexString:@"#1242FF"]] imgSize:CGSizeMake(kScreenWidth, 44)] forBarMetrics:UIBarMetricsDefault]; |
| 55 | + self.navigationController.navigationBar.tintColor = [UIColor blackColor]; |
| 56 | + } |
| 57 | + |
| 58 | +} |
| 59 | +- (void)dealloc { |
| 60 | +} |
| 61 | + |
| 62 | +- (void)setupUI { |
| 63 | + self.view.backgroundColor = [UIColor whiteColor]; |
| 64 | + self.title = @"IoT Video (局域网)"; |
| 65 | + |
| 66 | + CGFloat kWidthPadding = 16; |
| 67 | + CGFloat kItemHeight = 56; |
| 68 | + CGFloat kAPIBtnWidthHeight = 24; |
| 69 | + CGFloat kInputItemLeftPadding = 150; |
| 70 | + |
| 71 | + //第一行 |
| 72 | + UILabel *productIDLabel = [[UILabel alloc]init]; |
| 73 | + [productIDLabel setLabelFormateTitle:@"Product ID" font:[UIFont wcPfRegularFontOfSize:17] titleColorHexString:@"#000000" textAlignment:NSTextAlignmentLeft]; |
| 74 | + [self.view addSubview:productIDLabel]; |
| 75 | + [productIDLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
| 76 | + if (@available(iOS 11.0, *)) { |
| 77 | + make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(20); |
| 78 | + } else { |
| 79 | + // Fallback on earlier versions |
| 80 | + make.top.equalTo(self.view.mas_top).offset(64).offset(20); |
| 81 | + } |
| 82 | + make.left.equalTo(self.view.mas_left).offset(kWidthPadding); |
| 83 | + make.height.mas_equalTo(kItemHeight); |
| 84 | + }]; |
| 85 | + |
| 86 | + self.productID = [[UITextField alloc]init]; |
| 87 | + self.productID.textColor = [UIColor colorWithHexString:@"#7F7F7F"]; |
| 88 | + self.productID.returnKeyType = UIReturnKeyDone; |
| 89 | + self.productID.placeholder = @"请输入Product ID"; |
| 90 | + self.productID.delegate = self; |
| 91 | + self.productID.textAlignment = NSTextAlignmentLeft; |
| 92 | + self.productID.returnKeyType = UIReturnKeyDone; |
| 93 | + [self.view addSubview:self.productID]; |
| 94 | + [self.productID mas_makeConstraints:^(MASConstraintMaker *make) { |
| 95 | + make.left.equalTo(self.view.mas_left).offset(kInputItemLeftPadding); |
| 96 | + make.centerY.equalTo(productIDLabel); |
| 97 | + make.height.equalTo(productIDLabel); |
| 98 | + make.right.equalTo(self.view.mas_right).offset(-kWidthPadding - kAPIBtnWidthHeight); |
| 99 | + }]; |
| 100 | + |
| 101 | + UIView *line2 = [[UIView alloc]init]; |
| 102 | + line2.backgroundColor = [UIColor colorWithHexString:kVideoDemoPlaceColor]; |
| 103 | + [self.view addSubview:line2]; |
| 104 | + [line2 mas_makeConstraints:^(MASConstraintMaker *make) { |
| 105 | + make.left.equalTo(self.view.mas_left).offset(kWidthPadding); |
| 106 | + make.right.equalTo(self.view); |
| 107 | + make.top.equalTo(productIDLabel.mas_bottom); |
| 108 | + make.height.mas_equalTo(1); |
| 109 | + }]; |
| 110 | + |
| 111 | + //第二行 |
| 112 | + UILabel *clientTokenLabel = [[UILabel alloc]init]; |
| 113 | + [clientTokenLabel setLabelFormateTitle:@"Device Name" font:[UIFont wcPfRegularFontOfSize:17] titleColorHexString:@"#000000" textAlignment:NSTextAlignmentLeft]; |
| 114 | + [self.view addSubview:clientTokenLabel]; |
| 115 | + [clientTokenLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
| 116 | + make.left.equalTo(self.view.mas_left).offset(kWidthPadding); |
| 117 | + make.top.equalTo(line2.mas_bottom); |
| 118 | + make.height.mas_equalTo(kItemHeight); |
| 119 | + }]; |
| 120 | + |
| 121 | + self.devicenname = [[UITextField alloc]init]; |
| 122 | + self.devicenname.textColor = [UIColor colorWithHexString:@"#7F7F7F"]; |
| 123 | + self.devicenname.placeholder = @"请输入Device Name"; |
| 124 | + self.devicenname.delegate = self; |
| 125 | +// self.clientToken.secureTextEntry = YES; |
| 126 | + self.devicenname.textAlignment = NSTextAlignmentLeft; |
| 127 | + self.devicenname.returnKeyType = UIReturnKeyDone; |
| 128 | + [self.view addSubview:self.devicenname]; |
| 129 | + [self.devicenname mas_makeConstraints:^(MASConstraintMaker *make) { |
| 130 | + make.left.equalTo(self.view.mas_left).offset(kInputItemLeftPadding); |
| 131 | + make.centerY.equalTo(clientTokenLabel); |
| 132 | + make.height.equalTo(clientTokenLabel); |
| 133 | + make.right.equalTo(self.view.mas_right).offset(-kWidthPadding); |
| 134 | + }]; |
| 135 | + |
| 136 | + UIView *line3 = [[UIView alloc]init]; |
| 137 | + line3.backgroundColor = [UIColor colorWithHexString:kVideoDemoPlaceColor]; |
| 138 | + [self.view addSubview:line3]; |
| 139 | + [line3 mas_makeConstraints:^(MASConstraintMaker *make) { |
| 140 | + make.top.equalTo(clientTokenLabel.mas_bottom); |
| 141 | + make.height.mas_equalTo(1); |
| 142 | + make.left.right.equalTo(line2); |
| 143 | + }]; |
| 144 | + |
| 145 | + //第三行 |
| 146 | + UILabel *p2pinfoLabel = [[UILabel alloc]init]; |
| 147 | + [p2pinfoLabel setLabelFormateTitle:@"XP2P Info" font:[UIFont wcPfRegularFontOfSize:17] titleColorHexString:@"#000000" textAlignment:NSTextAlignmentLeft]; |
| 148 | + [self.view addSubview:p2pinfoLabel]; |
| 149 | + [p2pinfoLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
| 150 | + make.left.equalTo(self.view.mas_left).offset(kWidthPadding); |
| 151 | + make.top.equalTo(line3.mas_bottom); |
| 152 | + make.height.mas_equalTo(kItemHeight); |
| 153 | + }]; |
| 154 | + |
| 155 | + self.xp2pinfo = [[UITextField alloc]init]; |
| 156 | + self.xp2pinfo.textColor = [UIColor colorWithHexString:@"#7F7F7F"]; |
| 157 | + self.xp2pinfo.placeholder = @"请输入XP2P Info"; |
| 158 | + self.xp2pinfo.delegate = self; |
| 159 | +// self.clientToken.secureTextEntry = YES; |
| 160 | + self.xp2pinfo.textAlignment = NSTextAlignmentLeft; |
| 161 | + self.xp2pinfo.returnKeyType = UIReturnKeyDone; |
| 162 | + [self.view addSubview:self.xp2pinfo]; |
| 163 | + [self.xp2pinfo mas_makeConstraints:^(MASConstraintMaker *make) { |
| 164 | + make.left.equalTo(self.view.mas_left).offset(kInputItemLeftPadding); |
| 165 | + make.centerY.equalTo(p2pinfoLabel); |
| 166 | + make.height.equalTo(p2pinfoLabel); |
| 167 | + make.right.equalTo(self.view.mas_right).offset(-kWidthPadding); |
| 168 | + }]; |
| 169 | + |
| 170 | + UIView *line4 = [[UIView alloc]init]; |
| 171 | + line4.backgroundColor = [UIColor colorWithHexString:kVideoDemoPlaceColor]; |
| 172 | + [self.view addSubview:line4]; |
| 173 | + [line4 mas_makeConstraints:^(MASConstraintMaker *make) { |
| 174 | + make.top.equalTo(p2pinfoLabel.mas_bottom); |
| 175 | + make.height.mas_equalTo(1); |
| 176 | + make.left.right.equalTo(line2); |
| 177 | + }]; |
| 178 | + |
| 179 | + UIButton *detectDeviceBtn = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 180 | + detectDeviceBtn.backgroundColor = [UIColor colorWithHexString:kVideoDemoMainThemeColor]; |
| 181 | + [detectDeviceBtn setButtonFormateWithTitlt:@"连接设备" titleColorHexString:@"#FFFFFF" font:[UIFont wcPfRegularFontOfSize:17]]; |
| 182 | + [detectDeviceBtn addTarget:self action:@selector(detectEquipment) forControlEvents:UIControlEventTouchUpInside]; |
| 183 | + [self.view addSubview:detectDeviceBtn]; |
| 184 | + [detectDeviceBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
| 185 | + make.left.equalTo(self.view.mas_left).offset(kWidthPadding); |
| 186 | + make.right.equalTo(self.view.mas_right).offset(-kWidthPadding); |
| 187 | + make.top.equalTo(line4.mas_bottom).offset(30); |
| 188 | + make.height.mas_equalTo(45); |
| 189 | + }]; |
| 190 | + |
| 191 | + [self judgeAutoFillInputInfo]; |
| 192 | +} |
| 193 | + |
| 194 | +- (void)judgeAutoFillInputInfo { |
| 195 | + |
| 196 | + self.productID.text = [TIoTCoreUserManage shared].demoAreaNetProductID; |
| 197 | + self.devicenname.text = [TIoTCoreUserManage shared].demoAreaNetClientToken; |
| 198 | + self.xp2pinfo.text = [TIoTCoreUserManage shared].demoAreaNetClientToken; |
| 199 | + |
| 200 | +} |
| 201 | + |
| 202 | +- (void)saveInputInfo { |
| 203 | + |
| 204 | + [TIoTCoreUserManage shared].demoAreaNetProductID = self.productID.text; |
| 205 | + [TIoTCoreUserManage shared].demoAreaNetClientToken = self.devicenname.text; |
| 206 | +} |
| 207 | + |
| 208 | +///MARK: 探测设备 |
| 209 | +- (void)detectEquipment { |
| 210 | + [self hideKeyBoard]; |
| 211 | + [self saveInputInfo]; |
| 212 | + |
| 213 | + TIoTDemoPreviewDeviceVC *previewDeviceVC = [[TIoTDemoPreviewDeviceVC alloc]init]; |
| 214 | + |
| 215 | + TIoTExploreOrVideoDeviceModel *model = [TIoTExploreOrVideoDeviceModel new]; model.DeviceName = self.devicenname.text; |
| 216 | + TIoTCoreAppEnvironment *env = [TIoTCoreAppEnvironment shareEnvironment]; |
| 217 | + env.cloudProductId = self.productID.text; |
| 218 | + previewDeviceVC.selectedModel = model; |
| 219 | + previewDeviceVC.mXp2pInfo = self.xp2pinfo.text; |
| 220 | + previewDeviceVC.isNVR = NO; |
| 221 | + [self.navigationController pushViewController:previewDeviceVC animated:YES]; |
| 222 | +} |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | +#pragma mark - UITextField delegate |
| 227 | +- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { |
| 228 | + [self hideKeyBoard]; |
| 229 | + return YES; |
| 230 | +} |
| 231 | + |
| 232 | +- (void)hideKeyBoard { |
| 233 | + [self.productID resignFirstResponder]; |
| 234 | + [self.devicenname resignFirstResponder]; |
| 235 | + [self.xp2pinfo resignFirstResponder]; |
| 236 | +} |
| 237 | + |
| 238 | +- (BOOL)textFieldShouldReturn:(UITextField *)textField { |
| 239 | + [self hideKeyBoard]; |
| 240 | + return YES; |
| 241 | +} |
| 242 | + |
| 243 | +@end |
0 commit comments