AdminAuthPopupView.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // AdminAuthPopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 1/13/16.
  6. // Copyright (c) 2016 ntels. All rights reserved.
  7. //
  8. @import AVFoundation;
  9. #import "JDObject.h"
  10. #import "RequestHandler.h"
  11. #import "JDJSONModel.h"
  12. #import "CustomLabel.h"
  13. #import "CustomTextField.h"
  14. #import "ValidateUtil.h"
  15. #import "AdminAuthPopupView.h"
  16. #define ksSetTopAdminPasswd @"198877"
  17. @interface AdminAuthPopupView () <CustomTextFieldDelegate> {
  18. }
  19. @end
  20. @implementation AdminAuthPopupView
  21. - (id)initFromNib {
  22. for (UIView *view in [CommonUtil nibViews:@"AdminAuthPopupView"]) {
  23. if ([view isKindOfClass:[AdminAuthPopupView class]]) {
  24. self = (AdminAuthPopupView *)view;
  25. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  26. self.frame = [UIScreen mainScreen].bounds;
  27. self.lblTitle.text = @"관리자 비밀번호";
  28. _txtPwd.secureTextEntry = YES;
  29. _txtPwd.keyboardType = UIKeyboardTypeDefault;
  30. _txtPwd.returnKeyType = UIReturnKeyDone;
  31. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  32. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  33. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  34. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  35. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. //Localization
  37. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  38. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  39. }
  40. }
  41. return self;
  42. }
  43. - (void)didMoveToSuperview {
  44. _txtPwd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  45. }
  46. - (void)btnConfirmTouched:(id)sender {
  47. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypeNull title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  48. return;
  49. }
  50. if (![_txtPwd.text isEqualToString:ksSetTopAdminPasswd]) {
  51. [[JDFacade facade] toast:@"비밀번호가 틀렸습니다"];
  52. return;
  53. }
  54. AVAuthorizationStatus avAuthrizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  55. if (avAuthrizationStatus != AVAuthorizationStatusAuthorized) {//카메라 권한이 없을 경우,
  56. NSString *message = MSG_CAMERA_DISABLE;
  57. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:message delegate:nil OKButtonTitle:@"설정" cancelButtonTitle:@"취소"];
  58. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  59. if (buttonIndex == 0) {//OK - 이전화면으로
  60. NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  61. [[UIApplication sharedApplication] openURL:settingsURL];
  62. return;
  63. }
  64. }];
  65. }
  66. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"QRCodeViewController" storyboardName:@"HomeHub"];
  67. vc.providesPresentationContextTransitionStyle = YES;
  68. vc.definesPresentationContext = YES;
  69. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  70. [super btnConfirmTouched:sender];
  71. [[JDFacade facade].currentViewController presentViewController:vc animated:YES completion:nil];
  72. }
  73. #pragma mark - CustomTextField
  74. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  75. if ([textField isEqual:_txtPwd]) {
  76. [self btnConfirmTouched:nil];
  77. }
  78. return YES;
  79. }
  80. @end