JDFacade.m 25 KB

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