RCTBundleURLProvider.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <Foundation/Foundation.h>
  8. #if defined(__cplusplus)
  9. extern "C" {
  10. #endif
  11. extern NSString *const RCTBundleURLProviderUpdatedNotification;
  12. extern const NSUInteger kRCTBundleURLProviderDefaultPort;
  13. #if defined(__cplusplus)
  14. }
  15. #endif
  16. @interface RCTBundleURLProvider : NSObject
  17. /**
  18. * Set default settings on NSUserDefaults.
  19. */
  20. - (void)setDefaults;
  21. /**
  22. * Reset every settings to default.
  23. */
  24. - (void)resetToDefaults;
  25. /**
  26. * Return the server host. If its a development build and there's no jsLocation defined,
  27. * it will return the server host IP address
  28. */
  29. - (NSString *)packagerServerHost;
  30. #if RCT_DEV
  31. - (BOOL)isPackagerRunning:(NSString *)host;
  32. #endif
  33. /**
  34. * Returns the jsBundleURL for a given bundle entrypoint and
  35. * the fallback offline JS bundle if the packager is not running.
  36. */
  37. - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL * (^)(void))fallbackURLProvider;
  38. /**
  39. * Returns the jsBundleURL for a given bundle entrypoint and
  40. * the fallback offline JS bundle if the packager is not running.
  41. * if resourceName or extension are nil, "main" and "jsbundle" will be
  42. * used, respectively.
  43. */
  44. - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
  45. fallbackResource:(NSString *)resourceName
  46. fallbackExtension:(NSString *)extension;
  47. /**
  48. * Returns the jsBundleURL for a given bundle entrypoint and
  49. * the fallback offline JS bundle if the packager is not running.
  50. */
  51. - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName;
  52. /**
  53. * Returns the jsBundleURL for a given bundle entrypoint and
  54. * the fallback offline JS bundle. If resourceName or extension
  55. * are nil, "main" and "jsbundle" will be used, respectively.
  56. */
  57. - (NSURL *)jsBundleURLForFallbackResource:(NSString *)resourceName fallbackExtension:(NSString *)extension;
  58. /**
  59. * Returns the resourceURL for a given bundle entrypoint and
  60. * the fallback offline resource file if the packager is not running.
  61. */
  62. - (NSURL *)resourceURLForResourceRoot:(NSString *)root
  63. resourceName:(NSString *)name
  64. resourceExtension:(NSString *)extension
  65. offlineBundle:(NSBundle *)offlineBundle;
  66. /**
  67. * The IP address or hostname of the packager.
  68. */
  69. @property (nonatomic, copy) NSString *jsLocation;
  70. @property (nonatomic, assign) BOOL enableLiveReload;
  71. @property (nonatomic, assign) BOOL enableMinification;
  72. @property (nonatomic, assign) BOOL enableDev;
  73. + (instancetype)sharedSettings;
  74. /**
  75. Given a hostname for the packager and a bundle root, returns the URL to the js bundle. Generally you should use the
  76. instance method -jsBundleURLForBundleRoot:fallbackResource: which includes logic to guess if the packager is running
  77. and fall back to a pre-packaged bundle if it is not.
  78. */
  79. + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
  80. packagerHost:(NSString *)packagerHost
  81. enableDev:(BOOL)enableDev
  82. enableMinification:(BOOL)enableMinification;
  83. /**
  84. * Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
  85. * In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
  86. * resource if it is not: -resourceURLForResourceRoot:resourceName:resourceExtension:offlineBundle:
  87. */
  88. + (NSURL *)resourceURLForResourcePath:(NSString *)path packagerHost:(NSString *)packagerHost query:(NSString *)query;
  89. @end