From 5ef3b47ede2b1b861e5d6c4baae4a4d89dd9cea8 Mon Sep 17 00:00:00 2001 From: Nathan Azaria Date: Thu, 9 Jun 2016 07:01:42 -0700 Subject: [PATCH] Replaced CTLSettings with RCTBundleURLProvider internally Reviewed By: javache Differential Revision: D3398803 fbshipit-source-id: 1c5610a1e59f3fad4c57b0b280559f2ff2acf05a --- React/Base/RCTBundleURLProvider.h | 10 ++++++++++ React/Base/RCTBundleURLProvider.m | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTBundleURLProvider.h b/React/Base/RCTBundleURLProvider.h index 4ae517d6d..b1cf8e29b 100644 --- a/React/Base/RCTBundleURLProvider.h +++ b/React/Base/RCTBundleURLProvider.h @@ -18,6 +18,11 @@ extern NSString *const RCTBundleURLProviderUpdatedNotification; */ - (void)setDefaults; +/** + * Reset every settings to default. + */ +- (void)resetToDefaults; + /** * Returns the jsBundleURL for a given bundle entrypoint and * the fallback offline JS bundle if the packager is not running. @@ -25,6 +30,11 @@ extern NSString *const RCTBundleURLProviderUpdatedNotification; - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName; +/** + * Returns the URL of the packager server. + */ +- (NSURL *)packagerServerURL; + /** * The IP address or hostname of the packager. */ diff --git a/React/Base/RCTBundleURLProvider.m b/React/Base/RCTBundleURLProvider.m index f931b9a62..2f3bc3979 100644 --- a/React/Base/RCTBundleURLProvider.m +++ b/React/Base/RCTBundleURLProvider.m @@ -47,6 +47,14 @@ static NSString *const kDefaultPort = @"8081"; [self settingsUpdated]; } +- (void)resetToDefaults +{ + for (NSString *key in [[self defaults] allKeys]) { + [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; + } + [self setDefaults]; +} + - (BOOL)isPackagerRunning:(NSString *)host { if (RCT_DEV) { @@ -75,7 +83,6 @@ static NSString *serverRootWithHost(NSString *host) return nil; } - - (NSString *)packagerServerRoot { NSString *location = [self jsLocation]; @@ -91,6 +98,12 @@ static NSString *serverRootWithHost(NSString *host) } } +- (NSURL *)packagerServerURL +{ + NSString *root = [self packagerServerRoot]; + return root ? [NSURL URLWithString:root] : nil; +} + - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName { resourceName = resourceName ?: @"main";