FLEXManager+Networking.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // FLEXManager+Networking.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 2/1/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXManager+Networking.h"
  9. #import "FLEXManager+Private.h"
  10. #import "FLEXNetworkObserver.h"
  11. #import "FLEXNetworkRecorder.h"
  12. #import "FLEXObjectExplorerFactory.h"
  13. #import "NSUserDefaults+FLEX.h"
  14. @implementation FLEXManager (Networking)
  15. + (void)load {
  16. if (NSUserDefaults.standardUserDefaults.flex_registerDictionaryJSONViewerOnLaunch) {
  17. dispatch_async(dispatch_get_main_queue(), ^{
  18. // Register array/dictionary viewer for JSON responses
  19. [self.sharedManager setCustomViewerForContentType:@"application/json"
  20. viewControllerFutureBlock:^UIViewController *(NSData *data) {
  21. id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  22. if (jsonObject) {
  23. return [FLEXObjectExplorerFactory explorerViewControllerForObject:jsonObject];
  24. }
  25. return nil;
  26. }
  27. ];
  28. });
  29. }
  30. }
  31. - (BOOL)isNetworkDebuggingEnabled {
  32. return FLEXNetworkObserver.isEnabled;
  33. }
  34. - (void)setNetworkDebuggingEnabled:(BOOL)networkDebuggingEnabled {
  35. FLEXNetworkObserver.enabled = networkDebuggingEnabled;
  36. }
  37. - (NSUInteger)networkResponseCacheByteLimit {
  38. return FLEXNetworkRecorder.defaultRecorder.responseCacheByteLimit;
  39. }
  40. - (void)setNetworkResponseCacheByteLimit:(NSUInteger)networkResponseCacheByteLimit {
  41. FLEXNetworkRecorder.defaultRecorder.responseCacheByteLimit = networkResponseCacheByteLimit;
  42. }
  43. - (NSMutableArray<NSString *> *)networkRequestHostBlacklist {
  44. return FLEXNetworkRecorder.defaultRecorder.hostBlacklist;
  45. }
  46. - (void)setNetworkRequestHostBlacklist:(NSMutableArray<NSString *> *)networkRequestHostBlacklist {
  47. FLEXNetworkRecorder.defaultRecorder.hostBlacklist = networkRequestHostBlacklist;
  48. }
  49. - (void)setCustomViewerForContentType:(NSString *)contentType
  50. viewControllerFutureBlock:(FLEXCustomContentViewerFuture)viewControllerFutureBlock {
  51. NSParameterAssert(contentType.length);
  52. NSParameterAssert(viewControllerFutureBlock);
  53. NSAssert(NSThread.isMainThread, @"This method must be called from the main thread.");
  54. self.customContentTypeViewers[contentType.lowercaseString] = viewControllerFutureBlock;
  55. }
  56. @end