JDFacade.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. //
  2. // JDFacade.m
  3. // kneet2
  4. //
  5. // Created by Created by Jason Lee on 10/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. @import ObjectiveC.runtime;
  9. #import "JDFacade.h"
  10. #import "JDUserDefaults.h"
  11. #import "CypherUtil.h"
  12. #import "JDUUID.h"
  13. #import "CustomLoadingView.h"
  14. #import "CustomImageView.h"
  15. #import "CustomAlertView.h"
  16. #import "RequestHandler.h"
  17. //OpenSource
  18. #import "FLEXManager.h"
  19. #import "UIView+Toast.h"
  20. #import "JDProgressHUD.h"
  21. #import "LoginViewController.h"
  22. #import "Valet.h"
  23. #import "VALValet.h"
  24. @interface JDFacade () {
  25. VALValet *_valet;
  26. JDProgressHUD *_HUD;
  27. }
  28. @end
  29. @implementation JDFacade
  30. @synthesize tmpEmailId = _tmpEmailId;
  31. #pragma mark - Properties
  32. - (NSString *)deviceUUID {
  33. if (!_deviceUUID) {
  34. _deviceUUID = [[JDUUID UUIDHandler] getUUID];
  35. }
  36. return _deviceUUID;
  37. }
  38. - (NSString *)APNSToken {
  39. return _APNSToken ? _APNSToken : ksEmptyString;
  40. }
  41. - (NSString *)tmpEmailId {
  42. //FIXME : 다시 생각해바,
  43. NSString *enTmpEmailId = [self objectForKeyFromUserDefaults:USER_DEF_TMP_EMAIL];
  44. _tmpEmailId = [CypherUtil AES128Decrypt:enTmpEmailId WithKey:[CommonUtil bundleIdentifier]];
  45. return _tmpEmailId ? _tmpEmailId : ksEmptyString;
  46. }
  47. - (void)setTmpEmailId:(NSString *)tmpEmailId {
  48. NSString *enTmpEmailId = [CypherUtil AES128Encrypt:tmpEmailId WithKey:[CommonUtil bundleIdentifier]];
  49. [self storeObjectToUserDefaults:enTmpEmailId forKey:USER_DEF_TMP_EMAIL];
  50. }
  51. - (void)setLoginHomeGroup:(HomeGroupModel *)loginHomeGroup {
  52. _loginHomeGroup = loginHomeGroup;
  53. _loginUser.homegrpId = _loginHomeGroup.homegrpId;
  54. [RequestHandler handler].homegrpId = _loginHomeGroup.homegrpId;
  55. }
  56. - (void)setCurrentOperation:(NSOperation *)currentOperation {
  57. [CustomLoadingView loadingView].operation = currentOperation;
  58. }
  59. #pragma mark - View Facade
  60. - (AppDelegate *)appDelegate {
  61. return (AppDelegate *)[UIApplication sharedApplication].delegate;
  62. }
  63. #pragma mark - 화면 제어
  64. - (UIViewController *)currentViewController {
  65. id appDelegate = [UIApplication sharedApplication].delegate;
  66. UIViewController *vc = (UINavigationController *)[[appDelegate window] rootViewController];
  67. if (vc.presentedViewController) {
  68. vc = vc.presentedViewController;
  69. if ([vc isKindOfClass:[UINavigationController class]]) {
  70. NSArray *vcArray = ((UINavigationController *)vc).viewControllers;
  71. vc = [vcArray objectAtIndex:vcArray.count - 1];
  72. }
  73. return vc;
  74. }
  75. if (vc.presentingViewController && (vc.modalPresentationStyle == UIModalPresentationFullScreen)) {
  76. vc = vc.presentingViewController;
  77. }
  78. if ([vc isKindOfClass:[UINavigationController class]]) {
  79. NSArray *vcArray = ((UINavigationController *)vc).viewControllers;
  80. vc = [vcArray objectAtIndex:vcArray.count - 1];
  81. }
  82. return vc;
  83. }
  84. - (id)viewControllerOnNaviationController:(Class)viewControllerClass {
  85. UIViewController *targetVc = nil;
  86. UINavigationController *navigationController = self.currentViewController.navigationController;
  87. if (!navigationController) {
  88. navigationController = (UINavigationController *)self.currentViewController.presentingViewController;
  89. }
  90. if ([navigationController isKindOfClass:[UINavigationController class]]) {
  91. for (UIViewController *vc in navigationController.viewControllers) {
  92. if ([vc isKindOfClass:viewControllerClass]) {
  93. targetVc = vc;
  94. break;
  95. }
  96. }
  97. }
  98. return targetVc;
  99. }
  100. - (id)viewControllerOnPresentingViewController:(UIViewController *)pvc viewControllerClass:(Class)viewControllerClass {
  101. UIViewController *vc = pvc.presentingViewController;
  102. if (![vc isKindOfClass:viewControllerClass]) {
  103. vc = [self viewControllerOnPresentingViewController:vc viewControllerClass:viewControllerClass];
  104. }
  105. return vc;
  106. }
  107. #pragma mark - KeychainItem Wrapper
  108. static NSString *const ksKeychainIdentifier = @"KNEET2ACCOUNT";
  109. static NSString *const ksKeychainArchiveData = @"_archiveData";
  110. - (void)storeObjectToKeychain:(id)object forKey:(NSString *)aKey {
  111. if (!_valet) {
  112. _valet = [[VALValet alloc] initWithIdentifier:ksKeychainIdentifier accessibility:VALAccessibilityWhenUnlockedThisDeviceOnly];
  113. }
  114. NSMutableDictionary *dict = nil;
  115. NSData *archiveData = [_valet objectForKey:ksKeychainArchiveData];
  116. if (archiveData) {
  117. dict = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:archiveData];
  118. }
  119. if (!dict) {
  120. dict = [[NSMutableDictionary alloc] init];
  121. }
  122. [dict setObject:object forKey:aKey];
  123. archiveData = [NSKeyedArchiver archivedDataWithRootObject:dict];
  124. [_valet setObject:archiveData forKey:ksKeychainArchiveData];
  125. }
  126. - (id)objectForKeyFromKeychain:(NSString *)aKey {
  127. if (!_valet) {
  128. _valet = [[VALValet alloc] initWithIdentifier:ksKeychainIdentifier accessibility:VALAccessibilityWhenUnlockedThisDeviceOnly];
  129. }
  130. NSMutableDictionary *dict = nil;
  131. NSData *archiveData = [_valet objectForKey:ksKeychainArchiveData];
  132. id obj = nil;
  133. if (archiveData) {
  134. dict = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:archiveData];
  135. obj = [dict objectForKey:aKey];
  136. }
  137. return obj;
  138. }
  139. - (void)removeObjectAtKeychain:(NSString *)aKey {
  140. if (!_valet) {
  141. _valet = [[VALValet alloc] initWithIdentifier:ksKeychainIdentifier accessibility:VALAccessibilityWhenUnlockedThisDeviceOnly];
  142. }
  143. NSMutableDictionary *dict = nil;
  144. NSData *archiveData = [_valet objectForKey:ksKeychainArchiveData];
  145. if (archiveData) {
  146. NSMutableDictionary *dict = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:archiveData];
  147. [dict removeObjectForKey:aKey];
  148. }
  149. archiveData = [NSKeyedArchiver archivedDataWithRootObject:dict];
  150. [_valet setObject:archiveData forKey:ksKeychainArchiveData];
  151. }
  152. #pragma mark - UserDefautls - Local Store
  153. - (void)storeObjectToUserDefaults:(id)object forKey:(NSString *)aKey {
  154. [[JDUserDefaults defaults] syncronizeObject:object forKey:aKey];
  155. }
  156. - (id)objectForKeyFromUserDefaults:(NSString *)aKey {
  157. return [[JDUserDefaults defaults] objectForKey:aKey];
  158. }
  159. #pragma mark - Alert & Loading
  160. - (void)loadIndicator:(BOOL)showIndicator allowUserInteraction:(BOOL)allowUserInteracton {
  161. //로딩시 터치 방지
  162. if(showIndicator) {
  163. dispatch_async(dispatch_get_main_queue(), ^{
  164. [[JDFacade facade].currentViewController.view endEditing:YES];
  165. UIView *topView = [CommonUtil topView];
  166. [[CustomLoadingView loadingView] showInView:topView];
  167. });
  168. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
  169. } else {
  170. dispatch_async(dispatch_get_main_queue(), ^{
  171. [[CustomLoadingView loadingView] hide];
  172. });
  173. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  174. }
  175. }
  176. - (void)showLoadingWhileExecutingBlock:(dispatch_block_t)block completionHandler:(JDFacadeCompletionCallBackHandler)completion {
  177. [[CustomLoadingView loadingView] showInView:[CommonUtil topView] whileExecutingBlock:block completionHandler:completion];
  178. }
  179. #pragma mark - Alert UI
  180. - (void)alert:(NSString *)message {
  181. [self.currentViewController.view endEditing:YES];
  182. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  183. [alert show];
  184. }
  185. - (void)retryAlert:(NSString *)message target:(id)target selector:(SEL)selector {
  186. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:@"재시도"];
  187. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  188. if (buttonIndex == 1) {
  189. if ([target respondsToSelector:selector]) {
  190. [target performSelector:selector withObject:nil afterDelay:0.0f];
  191. }
  192. }
  193. }];
  194. }
  195. - (void)retryAlert:(NSString *)message target:(id)target selector:(SEL)selector arguments:(id)arguments,... {
  196. va_list args;
  197. va_start(args, arguments);
  198. NSInteger i = 0;
  199. NSMutableArray *argsArray = [[NSMutableArray alloc] init];
  200. [argsArray addObject:arguments];
  201. while ((arguments = va_arg(args, id)) != nil) {//루프 - 입력된 메시지를 받아옴.
  202. [argsArray addObject:arguments];
  203. i++;
  204. }
  205. va_end(args);
  206. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:@"재시도"];
  207. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  208. if (buttonIndex == 0) {
  209. if (target && selector) {
  210. NSMethodSignature *sig = [target methodSignatureForSelector:selector];
  211. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
  212. NSInteger index = 2;
  213. [invocation setTarget:target]; // index 0 (hidden)
  214. [invocation setSelector:selector]; //index 1 (hidden)
  215. for (id argument in argsArray) {
  216. [invocation setArgument:(void *)&argument atIndex:index++];
  217. }
  218. [invocation invoke];
  219. }
  220. }
  221. }];
  222. }
  223. - (void)alert:(NSString *)message completionHander:(JDFacadeCompletionCallBackHandler)completion {
  224. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  225. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  226. if (completion) {
  227. completion();
  228. }
  229. }];
  230. }
  231. - (void)fireLocalNotification:(NSString *)message {
  232. NSLog(@"fireLocalNotification %@", message);
  233. NSDate *now = [NSDate date];
  234. UILocalNotification *localNotif = [[UILocalNotification alloc] init];
  235. localNotif.fireDate = now;
  236. NSTimeZone* timezone = [NSTimeZone defaultTimeZone];
  237. localNotif.timeZone = timezone;
  238. localNotif.hasAction = YES;
  239. localNotif.alertBody = message;
  240. localNotif.alertAction = @"View";
  241. localNotif.soundName = UILocalNotificationDefaultSoundName;
  242. localNotif.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
  243. [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
  244. }
  245. - (void)toast:(NSString *)message {
  246. [[CommonUtil topView] makeToast:message];
  247. }
  248. #pragma mark - 화면이동 제어
  249. - (id)getRadioButtonStatus:(id)object {
  250. return objc_getAssociatedObject(object, ksCustomRadioButtonStatus);
  251. }
  252. - (void)setRadioButtonStatus:(id)status object:(id)object {
  253. objc_setAssociatedObject(object, ksCustomRadioButtonStatus, status, OBJC_ASSOCIATION_COPY_NONATOMIC); //for radio box
  254. }
  255. - (id)getCheckBoxStatus:(id)object {
  256. return objc_getAssociatedObject(object, ksCustomCheckBoxStatus);
  257. }
  258. - (void)setCheckBoxStatus:(id)status object:(id)object {
  259. objc_setAssociatedObject(object, ksCustomCheckBoxStatus, status, OBJC_ASSOCIATION_COPY_NONATOMIC); //for check box
  260. }
  261. - (void)presentViewControllerByPush:(UIViewController *)vc {
  262. CATransition *transition = [CATransition animation];
  263. transition.duration = kfTransitionRightDur;
  264. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  265. transition.type = kCATransitionPush;
  266. transition.subtype = kCATransitionFromRight;
  267. [self.currentViewController.view.window.layer addAnimation:transition forKey:nil];
  268. [self.currentViewController presentViewController:vc animated:NO completion:nil];
  269. }
  270. - (void)presentViewControllerByPush:(UIViewController *)vc pvc:(UIViewController *)pvc {
  271. CATransition *transition = [CATransition animation];
  272. transition.duration = kfTransitionRightDur;
  273. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  274. transition.type = kCATransitionPush;
  275. transition.subtype = kCATransitionFromRight;
  276. [pvc.view.window.layer addAnimation:transition forKey:nil];
  277. [pvc presentViewController:vc animated:NO completion:nil];
  278. }
  279. - (UIViewController *)presentedViewController:(UIViewController *)vc {
  280. UIViewController *presentedViewController = vc.presentedViewController;
  281. if (presentedViewController) {
  282. return [self presentedViewController:presentedViewController];
  283. }
  284. return vc;
  285. }
  286. - (void)dismissViewControllerByPush:(UIViewController *)vc {
  287. CATransition *transition = [CATransition animation];
  288. transition.duration = kfTransitionRightDur;
  289. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  290. transition.type = kCATransitionPush;
  291. transition.subtype = kCATransitionFromLeft;
  292. UIViewController *presentedViewController = [self presentedViewController:vc];
  293. [presentedViewController.view.window.layer addAnimation:transition forKey:nil];
  294. [vc dismissViewControllerAnimated:NO completion:nil];
  295. }
  296. - (void)dismissViewControllerByPush:(UIViewController *)vc completion:(JDFacadeCompletionCallBackHandler)completion {
  297. CATransition *transition = [CATransition animation];
  298. transition.duration = kfTransitionRightDur;
  299. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  300. transition.type = kCATransitionPush;
  301. transition.subtype = kCATransitionFromLeft;
  302. UIViewController *presentedViewController = [self presentedViewController:vc];
  303. [presentedViewController.view.window.layer addAnimation:transition forKey:nil];
  304. [vc dismissViewControllerAnimated:NO completion:^{
  305. if (completion) {
  306. completion();
  307. }
  308. }];
  309. }
  310. - (void)dismissAllViewControllers {
  311. UIViewController *vc = self.currentViewController;
  312. if (vc.presentingViewController) {
  313. [vc dismissViewControllerAnimated:NO completion:^{
  314. [self dismissAllViewControllers];
  315. }];
  316. }
  317. }
  318. #pragma mark - UI Flow
  319. - (void)gotoLoginView {
  320. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  321. [JDFacade facade].appDelegate.window.rootViewController = vc;
  322. }
  323. //- (void)gotoLoginViewWithExpiring {
  324. // LoginViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  325. // [vc actionAfterLogout];
  326. //}
  327. //
  328. - (void)logout {
  329. LoginViewController *lvc = (LoginViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"LoginViewController" storyboardName:@"Main"];
  330. [lvc requestLogout];
  331. }
  332. //
  333. //- (void)loadInvitationView {
  334. // UIViewController *pvc = [JDFacade facade].currentViewController.presentedViewController;
  335. // if (!pvc) {
  336. // pvc = [JDFacade facade].currentViewController;
  337. // }
  338. //
  339. // UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"InvitationListViewController" storyboardName:@"Main"];
  340. // [[JDFacade facade] presentViewControllerByPush:vc pvc:pvc];
  341. //}
  342. //
  343. //- (void)checkDefaultHome {
  344. // if (!self.loginUser) {//로그인이 안된 경우, 불필요함.
  345. // return;
  346. // }
  347. //
  348. // [self updateHomegrpListForLoginUser:^{
  349. // //1. 다른 홈이 있는지 확인 - 정렬순서대로 기본홈을 설정 - currentHome
  350. // if (self.loginUser.homegrpList && self.loginUser.homegrpList.count) {
  351. // self.loginHomeGroup = self.loginUser.homegrpList[0];
  352. // [self gotoWishMenu:KNMenuIdDashboard];
  353. // return;
  354. // }
  355. //
  356. // //2. 다른 홈이 없는 경우, - 홈만들기로 이동함.
  357. // CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") message:NSLocalizedString(@"현재 참여 중인 홈이 없습니다\n새로운 홈 만들기를 시작할까요?", @"현재 참여 중인 홈이 없습니다\n새로운 홈 만들기를 시작할까요?") delegate:nil OKButtonTitle:NSLocalizedString(@"확인", @"확인") cancelButtonTitle:NSLocalizedString(@"취소", @"취소")];
  358. // [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  359. // if (buttonIndex == 0) {//OK
  360. // [self gotoStartHome:NO];
  361. // } else {
  362. // [self logout];
  363. // }
  364. // }];
  365. // }];
  366. //}
  367. - (void)gotoStartHome:(BOOL)canGoBack {
  368. // StartHomeViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"StartHomeViewController" storyboardName:@"SignUp"];
  369. // vc.canGoBack = canGoBack;
  370. // [[JDFacade facade] presentViewControllerByPush:vc pvc:self.currentViewController];
  371. }
  372. - (void)gotoWishMenu:(KNMenuId)menuId {
  373. [self gotoWishMenu:menuId completion:nil];
  374. }
  375. - (void)gotoWishMenu:(KNMenuId)menuId completion:(JDFacadeCompletionCallBackHandler)completion {
  376. self.wishMenuId = menuId;
  377. UIViewController *vc = self.appDelegate.window.rootViewController;
  378. if (vc.presentedViewController || (vc.presentingViewController && (vc.modalPresentationStyle == UIModalPresentationFullScreen))){
  379. [vc dismissViewControllerAnimated:YES completion:nil];
  380. }
  381. // MenuViewController *mvc = [JDFacade facade].menuViewController;
  382. // [mvc gotoWishMenu:self.wishMenuId completion:completion];
  383. }
  384. //- (void)updateHomegrpListForLoginUser:(JDFacadeCompletionCallBackHandler)completion {
  385. //
  386. // NSDictionary *parameter = @{@"device_sn": [JDFacade facade].deviceUUID};
  387. //
  388. // dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  389. // HomeGroupListModel *homegrpList = [[RequestHandler handler] sendSyncGetRequestAPIPath:API_GET_HOMEGROUP parameters:parameter
  390. // modelClass:[HomeGroupListModel class] showLoadingView:@(YES)];
  391. //
  392. //
  393. // // NSLog(@"%s\n %@", __PRETTY_FUNCTION__, homegrpList);
  394. // //홈그룹을 설정함.
  395. // self.loginUser.homegrpList = homegrpList && homegrpList.homegrpList ? homegrpList.homegrpList : nil;
  396. //
  397. // //로그인 홈을 지정함.
  398. // for (HomeGroupModel *homegrp in self.loginUser.homegrpList) {
  399. // if ([self.loginUser.homegrpId isEqualToString:homegrp.homegrpId]) {
  400. // self.loginHomeGroup = homegrp;
  401. // break;
  402. // }
  403. // }
  404. //
  405. //// [[LocationHandler handler] resetAllMonitoredRegions]; //현재 앱이 구동 중이면, 위치 센서를 다시 등록해야함.
  406. //// [[LocationHandler handler] registerGeofencingForHomeGroupIndex:0]; //모든 홈 그룹을 다시 모니터링 등록 - 루프
  407. //
  408. // if (completion) {
  409. // completion();
  410. // }
  411. // });
  412. //}
  413. - (void)updateLoginInfo:(JDFacadeCompletionCallBackHandler)completion {
  414. NSLog(@"%s\n %@", __PRETTY_FUNCTION__, [JDFacade facade].deviceUUID);
  415. NSDictionary *parameter = @{@"device_sn": [JDFacade facade].deviceUUID,
  416. @"device_token": [JDFacade facade].APNSToken ? [JDFacade facade].APNSToken : ksEmptyString,
  417. @"os_type": MOBILE_DEVICE_TYPE};
  418. NSString *path = [NSString stringWithFormat:API_GET_SIGN_IN_AUTO];
  419. // dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  420. // LoginModel *loginInfo = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:parameter
  421. // modelClass:[LoginModel class] showLoadingView:@(YES)];
  422. // if (loginInfo) {
  423. // [JDFacade facade].loginUser = loginInfo;
  424. // }
  425. //
  426. // if (completion) {
  427. // completion();
  428. // }
  429. // });
  430. }
  431. - (void)alertLocationServiceDisabled {
  432. NSString *message = MSG_LOCATION_DISABLE;
  433. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") delegate:nil OKButtonTitle:NSLocalizedString(@"설정", @"설정") cancelButtonTitle:NSLocalizedString(@"취소", @"취소") message:message, nil];
  434. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  435. if (buttonIndex == 0) {//OK
  436. NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  437. [[UIApplication sharedApplication]openURL:settingsURL];
  438. }
  439. }];
  440. }
  441. - (void)alertCameraPermissionDisabled {
  442. NSString *message = MSG_CAMERA_DISABLE;
  443. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") delegate:nil OKButtonTitle:NSLocalizedString(@"설정", @"설정") cancelButtonTitle:NSLocalizedString(@"취소", @"취소") message:message, nil];
  444. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  445. if (buttonIndex == 0) {//OK
  446. NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  447. [[UIApplication sharedApplication]openURL:settingsURL];
  448. }
  449. }];
  450. }
  451. #pragma mark - Debug
  452. - (void)showFlex {
  453. [[FLEXManager sharedManager] showExplorer];
  454. }
  455. - (BOOL)redirectNSLog {
  456. // Create log file
  457. NSDate *date = [NSDate date];
  458. NSDateFormatter *df = [CommonUtil dateFormatter];
  459. [df setDateFormat:@"yyyyMMddHHmmss"];
  460. NSString *sdate = [df stringFromDate:date];
  461. NSString *logPath = [NSString stringWithFormat:@"%@/log_%@.txt", NSTemporaryDirectory(), sdate];
  462. [@"" writeToFile:logPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  463. id fileHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
  464. if (!fileHandle) {
  465. NSLog(@"Opening log failed");
  466. return NO;
  467. }
  468. // Redirect stderr
  469. int err = dup2([fileHandle fileDescriptor], STDERR_FILENO);
  470. if (!err) {
  471. NSLog(@"Couldn't redirect stderr");
  472. return NO;
  473. }
  474. return YES;
  475. }
  476. #pragma mark - Singleton
  477. + (JDFacade *)facade {
  478. static JDFacade *sharedJSFacade = nil;
  479. static dispatch_once_t onceToken;
  480. dispatch_once(&onceToken, ^{
  481. sharedJSFacade = [[self alloc] init];
  482. });
  483. return sharedJSFacade;
  484. }
  485. - (id)init {
  486. if (self = [super init]) {
  487. }
  488. return self;
  489. }
  490. @end