IntroViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "IntroViewController.h"
  10. @interface IntroViewController () {
  11. }
  12. @end
  13. #pragma mark - Class Definition
  14. @implementation IntroViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. [self initUI];
  19. NSLog(@"%s\n applicationState = %zd", __PRETTY_FUNCTION__, [UIApplication sharedApplication].applicationState);
  20. if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) {
  21. [self prepareViewDidLoad];
  22. }
  23. }
  24. - (void)initUI {
  25. NSString *test = @"test";
  26. NSLog(@"%s\n %@", __PRETTY_FUNCTION__, test);
  27. DDLogError(@"test colors");
  28. }
  29. - (void)prepareViewDidLoad {
  30. }
  31. - (void)viewDidAppear:(BOOL)animated {
  32. [super viewDidAppear: animated];
  33. [self performSelector:@selector(requestVersionInfo) withObject:nil afterDelay:0.0f];
  34. //
  35. //#ifndef PRODUCT_MODE
  36. //
  37. // ServerPopTableView *spopup = [[ServerPopTableView alloc] initFromNib];
  38. // [spopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  39. // if (buttonIndex == 0) {//OK
  40. // [self performSelector:@selector(requestVersionInfo) withObject:nil afterDelay:0.0f];
  41. // }
  42. // }];
  43. //
  44. //#else
  45. //
  46. // [self performSelector:@selector(requestVersionInfo) withObject:nil afterDelay:0.0f];
  47. //#endif
  48. }
  49. #pragma mark - Main Logic
  50. - (void)requestVersionInfo {
  51. //parameters
  52. NSDictionary *parameter = @{@"os_type": MOBILE_DEVICE_TYPE,
  53. @"store_code": APPSTORE_TYPE,
  54. @"app_version": [CommonUtil applicationShortVersion]};
  55. NSString *path = [NSString stringWithFormat:API_GET_APP_VERSION];
  56. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  57. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  58. return;
  59. }
  60. JDJSONModel *result = (JDJSONModel *) responseObject;
  61. if (result) {//API 성공 ,
  62. if ([result.resultCode isEqualToString:@"99"]) {//사용불가
  63. //앱 업그레이드 유도
  64. [[JDFacade facade] alert:MSG_ALERT_APP_UPDATE completionHander:^{
  65. NSString *appURL = URL_APP_UPDATE;
  66. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];
  67. }];
  68. } else {
  69. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  70. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  71. [JDFacade facade].appDelegate.window.rootViewController = vc;
  72. });
  73. }
  74. }
  75. } failure:^(id errorObject) {
  76. JDErrorModel *error = (JDErrorModel *)errorObject;
  77. [[JDFacade facade] alert:error.errorMessage];
  78. }];
  79. }
  80. #pragma mark - UI Events
  81. #pragma mark - MemoryWarning
  82. - (void)didReceiveMemoryWarning
  83. {
  84. [super didReceiveMemoryWarning];
  85. // Dispose of any resources that can be recreated.
  86. }
  87. @end