IntroViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // IntroViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 9/16/15.
  6. // Copyright (c) 2015 Jason Lee. All rights reserved.
  7. //
  8. #import "RequestHandler.h"
  9. #import "NetworkServiceHandler.h"
  10. #import "CustomImageView.h"
  11. #import "NSString-Addtions.h"
  12. #import "IntroViewController.h"
  13. @interface IntroViewController () <NetworkServiceHandlerDelegate> {
  14. NSDate *_elapsedDate;
  15. }
  16. @end
  17. #pragma mark - Class Definition
  18. @implementation IntroViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self initUI];
  23. _elapsedDate = [NSDate systemDate];
  24. NSLog(@"%s\n applicationState = %zd", __PRETTY_FUNCTION__, [UIApplication sharedApplication].applicationState);
  25. if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) {
  26. [self prepareViewDidLoad];
  27. }
  28. }
  29. - (void)initUI {
  30. UIImage *splashImage = nil;
  31. CGRect screen = [UIScreen mainScreen].bounds;
  32. if (screen.size.height == 667.0f) {//iphone6
  33. splashImage = [UIImage imageNamed:@"Brand Assets-800-667h"];
  34. } else if (screen.size.height == 736.0f) {//iphone6 plus
  35. splashImage = [UIImage imageNamed:@"Brand Assets-800-Portrait-736h"];
  36. } else if (screen.size.height == 480) {//iphone4s
  37. splashImage = [UIImage imageNamed:@"Brand Assets-700"];
  38. if (!IS_IPAD) {
  39. _constraintLableLtdBottom = [_constraintLableLtdBottom setMutltiplier:0.833f];
  40. }
  41. } else {//iphone5 over
  42. splashImage = [UIImage imageNamed:@"Brand Assets-700-568h"];
  43. }
  44. [_imgvSplash setImage:splashImage];
  45. }
  46. - (void)prepareViewDidLoad {
  47. }
  48. - (void)viewDidAppear:(BOOL)animated {
  49. [super viewDidAppear: animated];
  50. // if ([NetworkServiceHandler.handler startSearchBonjourServices])
  51. // {
  52. // NSLog(@"mdns 찾기");
  53. // NetworkServiceHandler.handler.delegate = self;
  54. // }
  55. // else
  56. // {
  57. // NSLog(@"mdns 찾기2");
  58. // [self requestVersionInfo];
  59. // }
  60. [self requestVersionInfo];
  61. }
  62. #pragma mark - Main Logic
  63. - (NSInteger)elapsedSecondsFromNow {
  64. NSInteger seconds = 0;
  65. if (_elapsedDate) {
  66. NSTimeInterval elapsed = [[NSDate systemDate] timeIntervalSinceDate:_elapsedDate];
  67. seconds = elapsed;
  68. }
  69. return seconds;
  70. }
  71. - (void)requestVersionInfo {
  72. if ([self elapsedSecondsFromNow] < 2) {
  73. [self performSelector:@selector(requestVersionInfo) withObject:nil afterDelay:0.2f];
  74. return;
  75. }
  76. //parameters
  77. NSDictionary *parameter = @{@"os_type": MOBILE_DEVICE_TYPE,
  78. @"store_code": APPSTORE_TYPE,
  79. @"app_version": [CommonUtil applicationShortVersion],
  80. @"service_id": MOBILE_SERVICE_ID};
  81. NSString *path = [NSString stringWithFormat:API_GET_APP_VERSION];
  82. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  83. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  84. return;
  85. }
  86. JDJSONModel *result = (JDJSONModel *) responseObject;
  87. if (result) {//API 성공 ,
  88. // if ([result.resultCode isEqualToString:@"99"]) {//사용불가
  89. if ([result.resultCode isEqualToString:@"999"]) {//사용불가
  90. //앱 업그레이드 유도
  91. [[JDFacade facade] alert:MSG_ALERT_APP_UPDATE completionHander:^{
  92. NSString *appURL = URL_APP_UPDATE;
  93. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];
  94. }];
  95. } else {
  96. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  97. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  98. [JDFacade facade].appDelegate.window.rootViewController = vc;
  99. });
  100. }
  101. }
  102. } failure:^(id errorObject) {
  103. JDErrorModel *error = (JDErrorModel *)errorObject;
  104. [[JDFacade facade] alert:error.errorMessage];
  105. }];
  106. }
  107. #pragma mark - NetworkServiceHandler Delegate
  108. - (void)didSucceedPublishService {
  109. [self requestVersionInfo];
  110. }
  111. - (void)didSucceedPublishService:(NSArray *)arrService
  112. {
  113. [self requestVersionInfo];
  114. NSLog(@"Result : %@", arrService);
  115. for (NSNetService *service in arrService) {
  116. NSDictionary* dict = [NSNetService dictionaryFromTXTRecordData:[service TXTRecordData]];
  117. SHOW_DICTIONARY_INFO(dict);
  118. NSLog(@"manufacturer : %@", [NSString stringWithUTF8Data:dict[@"model_number"]]);
  119. // [[JDFacade facade] alert:dict[@"manufacturer"]];
  120. }
  121. [NetworkServiceHandler.handler stopSearchBonjourServices];
  122. [self requestVersionInfo];
  123. }
  124. - (void)didFailPublishService:(id)errorInfo {
  125. NSLog(@"%s\n %@", __PRETTY_FUNCTION__, errorInfo);
  126. [self requestVersionInfo];
  127. }
  128. #pragma mark - MemoryWarning
  129. - (void)viewDidDisappear:(BOOL)animated {
  130. NetworkServiceHandler.handler.delegate = nil;
  131. }
  132. - (void)didReceiveMemoryWarning
  133. {
  134. [super didReceiveMemoryWarning];
  135. // Dispose of any resources that can be recreated.
  136. }
  137. @end