APLoginConfigVC.mm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // APLoginConfigVC.m
  3. // FunSDKDemo
  4. //
  5. // Created by Megatron on 2019/2/28.
  6. // Copyright © 2019 Megatron. All rights reserved.
  7. //
  8. #import "APLoginConfigVC.h"
  9. #import <Masonry/Masonry.h>
  10. #import <FunSDK/FunSDK.h>
  11. #import "Header.h"
  12. @interface APLoginConfigVC ()
  13. @property (nonatomic,strong) UITextField *tfWiFiName;
  14. @property (nonatomic,strong) UITextField *tfPassword;
  15. @property (nonatomic,strong) UIButton *btnConfirm;
  16. @property (nonatomic,assign) int msgHandle;
  17. @end
  18. @implementation APLoginConfigVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title = @"设备AP直连配网";
  22. self.view.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
  23. self.msgHandle = FUN_RegWnd((__bridge void*)self);
  24. [self.view addSubview:self.tfWiFiName];
  25. [self.view addSubview:self.tfPassword];
  26. [self.view addSubview:self.btnConfirm];
  27. [self myLayout];
  28. }
  29. #pragma mark - EventAction
  30. - (void)btnConfirmClicked{
  31. [SVProgressHUD show];
  32. FUN_DevStartWifiConfigByAPLogin(self.msgHandle, "192.168.10.1:34567", self.tfWiFiName.text.UTF8String, self.tfPassword.text.UTF8String, 180000);
  33. // 这个接口没有回调 自己检测wifi连接断开时 说明配置已经成功 设备也会有相应提示音
  34. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  35. [SVProgressHUD dismiss];
  36. });
  37. }
  38. #pragma mark - Layout
  39. - (void)myLayout{
  40. [self.tfWiFiName mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.centerX.equalTo(self);
  42. make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5);
  43. make.height.mas_equalTo(40);
  44. make.bottom.equalTo(self.tfPassword.mas_top).mas_offset(-10);
  45. }];
  46. [self.tfPassword mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerX.equalTo(self);
  48. make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5);
  49. make.height.mas_equalTo(40);
  50. make.centerY.equalTo(self);
  51. }];
  52. [self.btnConfirm mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.centerX.equalTo(self);
  54. make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5);
  55. make.height.mas_equalTo(40);
  56. make.top.equalTo(self.tfPassword.mas_bottom).mas_offset(40);
  57. }];
  58. }
  59. #pragma mark - LazyLoad
  60. - (UITextField *)tfWiFiName{
  61. if (!_tfWiFiName) {
  62. _tfWiFiName = [[UITextField alloc] init];
  63. _tfWiFiName.placeholder = @"输入WiFi名称";
  64. _tfWiFiName.textAlignment = NSTextAlignmentCenter;
  65. _tfWiFiName.layer.cornerRadius = 3;
  66. _tfWiFiName.layer.borderColor = [UIColor lightGrayColor].CGColor;
  67. _tfWiFiName.layer.borderWidth = 1;
  68. }
  69. return _tfWiFiName;
  70. }
  71. - (UITextField *)tfPassword{
  72. if (!_tfPassword) {
  73. _tfPassword = [[UITextField alloc] init];
  74. _tfPassword.placeholder = @"输入密码";
  75. _tfPassword.textAlignment = NSTextAlignmentCenter;
  76. _tfPassword.layer.cornerRadius = 3;
  77. _tfPassword.layer.borderColor = [UIColor lightGrayColor].CGColor;
  78. _tfPassword.layer.borderWidth = 1;
  79. }
  80. return _tfPassword;
  81. }
  82. - (UIButton *)btnConfirm{
  83. if (!_btnConfirm) {
  84. _btnConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
  85. [_btnConfirm setTitle:@"开始配置" forState:UIControlStateNormal];
  86. [_btnConfirm addTarget:self action:@selector(btnConfirmClicked) forControlEvents:UIControlEventTouchUpInside];
  87. [_btnConfirm setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  88. _btnConfirm.layer.cornerRadius = 3;
  89. _btnConfirm.layer.borderColor = [UIColor lightGrayColor].CGColor;
  90. _btnConfirm.layer.borderWidth = 1;
  91. }
  92. return _btnConfirm;
  93. }
  94. - (void)dealloc{
  95. FUN_UnRegWnd(self.msgHandle);
  96. }
  97. @end