IntroViewController.m 4.6 KB

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