IntroViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. NetworkServiceHandler.handler.delegate = self;
  51. } else {
  52. [self requestVersionInfo];
  53. }
  54. }
  55. #pragma mark - Main Logic
  56. - (NSInteger)elapsedSecondsFromNow {
  57. NSInteger seconds = 0;
  58. if (_elapsedDate) {
  59. NSTimeInterval elapsed = [[NSDate systemDate] timeIntervalSinceDate:_elapsedDate];
  60. seconds = elapsed;
  61. }
  62. return seconds;
  63. }
  64. - (void)requestVersionInfo {
  65. if ([self elapsedSecondsFromNow] < 2) {
  66. [self performSelector:@selector(requestVersionInfo) withObject:nil afterDelay:0.2f];
  67. return;
  68. }
  69. //parameters
  70. NSDictionary *parameter = @{@"os_type": MOBILE_DEVICE_TYPE,
  71. @"store_code": APPSTORE_TYPE,
  72. @"app_version": [CommonUtil applicationShortVersion],
  73. @"service_id": MOBILE_SERVICE_ID};
  74. NSString *path = [NSString stringWithFormat:API_GET_APP_VERSION];
  75. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  76. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  77. return;
  78. }
  79. JDJSONModel *result = (JDJSONModel *) responseObject;
  80. if (result) {//API 성공 ,
  81. if ([result.resultCode isEqualToString:@"99"]) {//사용불가
  82. //앱 업그레이드 유도
  83. [[JDFacade facade] alert:MSG_ALERT_APP_UPDATE completionHander:^{
  84. NSString *appURL = URL_APP_UPDATE;
  85. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];
  86. }];
  87. } else {
  88. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  89. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  90. [JDFacade facade].appDelegate.window.rootViewController = vc;
  91. });
  92. }
  93. }
  94. } failure:^(id errorObject) {
  95. JDErrorModel *error = (JDErrorModel *)errorObject;
  96. [[JDFacade facade] alert:error.errorMessage];
  97. }];
  98. }
  99. #pragma mark - NetworkServiceHandler Delegate
  100. - (void)didSucceedPublishService {
  101. [self requestVersionInfo];
  102. }
  103. - (void)didFailPublishService:(id)errorInfo {
  104. NSLog(@"%s\n %@", __PRETTY_FUNCTION__, errorInfo);
  105. [self requestVersionInfo];
  106. }
  107. #pragma mark - MemoryWarning
  108. - (void)viewDidDisappear:(BOOL)animated {
  109. NetworkServiceHandler.handler.delegate = nil;
  110. }
  111. - (void)didReceiveMemoryWarning
  112. {
  113. [super didReceiveMemoryWarning];
  114. // Dispose of any resources that can be recreated.
  115. }
  116. @end