ThingsAddCameraViewController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // ThingsAddCameraViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/26/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "ThingsAddCameraViewController.h"
  9. #import "JDObject.h"
  10. #import "ValidateUtil.h"
  11. #import "CustomTextField.h"
  12. #import "RequestHandler.h"
  13. #import "CustomLabel.h"
  14. #import "CustomButton.h"
  15. @interface ThingsAddCameraViewController () {
  16. }
  17. @end
  18. #pragma mark - Class Definition
  19. @implementation ThingsAddCameraViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self initUI];
  24. [self prepareViewDidLoad];
  25. }
  26. - (void)viewWillAppear:(BOOL)animated {
  27. [super viewWillAppear:animated];
  28. self.title = NSLocalizedString(@"새 장치 추가",nil);
  29. }
  30. - (void)initUI {
  31. //set tableview option
  32. self.tableView.delegate = self;
  33. self.tableView.dataSource = self;
  34. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. self.tableView.backgroundColor = [UIColor clearColor];
  36. self.tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  37. _txtFoscamURL.keyboardType = UIKeyboardTypeURL;
  38. _txtFoscamURL.returnKeyType = UIReturnKeyDone;
  39. _txtFoscamPort.keyboardType = UIKeyboardTypeNumberPad;
  40. _txtFoscamPort.returnKeyType = UIReturnKeyDone;
  41. _txtFoscamId.keyboardType = UIKeyboardTypeDefault;
  42. _txtFoscamId.returnKeyType = UIReturnKeyDone;
  43. _txtFoscamPwd.keyboardType = UIKeyboardTypeDefault;
  44. _txtFoscamPwd.returnKeyType = UIReturnKeyDone;
  45. _txtFoscamPwd.secureTextEntry = YES;
  46. _txtFoscamId.placeholder = NSLocalizedString(@"포스캠 아이디", @"포스캠 아이디");
  47. _txtFoscamPwd.placeholder = NSLocalizedString(@"비밀번호", @"비밀번호");
  48. _txtFoscamURL.placeholder = NSLocalizedString(@"접속 URL", @"접속 URL");
  49. _txtFoscamPort.placeholder = NSLocalizedString(@"포트번호", @"포트번호");
  50. //Localization
  51. _lblTitle.text = NSLocalizedString(@"FOSCAM을 현재 홈에 등록합니다", @"FOSCAM을 현재 홈에 등록합니다");
  52. _lblStep1Title.text = NSLocalizedString(@"Foscam의 매뉴얼에 따라 인터넷을 연결을 완료하세요", @"Foscam의 매뉴얼에 따라 인터넷을 연결을 완료하세요");
  53. _lblStep2Title.text = NSLocalizedString(@"아래 정보를 입력하면 바로 등록됩니다", @"아래 정보를 입력하면 바로 등록됩니다");
  54. _lblStep3Title.text = NSLocalizedString(@"● 포트포워딩이 되어있어야 합니다\n● 외부에서 연결하려면 URL에 DDNS 또는 외부접속 IP를 입력해주세요", @"● 포트포워딩이 되어있어야 합니다\n● 외부에서 연결하려면 URL에 DDNS 또는 외부접속 IP를 입력해주세요");
  55. [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  56. }
  57. - (void)prepareViewDidLoad {
  58. }
  59. #pragma mark - Main Logic
  60. - (void)requestRegisterCamera {
  61. //parameters
  62. NSDictionary *parameter = @{@"camera_id": _txtFoscamId.text,
  63. @"camera_password": _txtFoscamPwd.text,
  64. @"url": _txtFoscamURL.text,
  65. @"port": _txtFoscamPort.text};
  66. NSString *path = [NSString stringWithFormat:API_POST_CAMERA];
  67. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  68. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddCompleteViewController" storyboardName:@"Things"];
  69. [[JDFacade facade] presentViewControllerByPush:vc pvc:self];
  70. } failure:^(id errorObject) {
  71. JDErrorModel *error = (JDErrorModel *)errorObject;
  72. [[JDFacade facade] alert:error.errorMessage];
  73. }];
  74. }
  75. #pragma mark - UI Events
  76. - (IBAction)btnConfrimTouched:(id)sender {
  77. #ifdef DEBUG
  78. if ([_txtFoscamId.text isEmptyString]) {
  79. _txtFoscamId.text = @"ntels_cam";
  80. }
  81. if ([_txtFoscamPwd.text isEmptyString]) {
  82. _txtFoscamPwd.text = @"wotdemo2015@";
  83. }
  84. if ([_txtFoscamURL.text isEmptyString]) {
  85. _txtFoscamURL.text = @"http://192.168.2.100";
  86. }
  87. if ([_txtFoscamPort.text isEmptyString]) {
  88. _txtFoscamPort.text = @"8090";
  89. }
  90. //http://192.168.2.100:8090/
  91. // ID : ntels_cam
  92. // PW : wotdemo2015@
  93. #endif
  94. //1.validate
  95. if (![ValidateUtil validateTextfiled:_txtFoscamId type:ValidateTypeNull title:NSLocalizedString(@"포스캠 아이디", @"포스캠 아이디")]) {
  96. return;
  97. }
  98. if (![ValidateUtil validateTextfiled:_txtFoscamPwd type:ValidateTypeNull title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  99. return;
  100. }
  101. if (![ValidateUtil validateTextfiled:_txtFoscamURL type:ValidateTypeNull title:NSLocalizedString(@"접속 URL", @"접속 URL")]) {
  102. return;
  103. }
  104. if (![ValidateUtil validateTextfiled:_txtFoscamPort type:ValidateTypeNull title:NSLocalizedString(@"포트번호", @"포트번호")]) {
  105. return;
  106. }
  107. [self requestRegisterCamera];
  108. }
  109. #pragma mark - MemoryWarning
  110. - (void)didReceiveMemoryWarning
  111. {
  112. [super didReceiveMemoryWarning];
  113. // Dispose of any resources that can be recreated.
  114. }
  115. @end