From d1c3f5c4bfffbfb6ef19db785b4692ddf86c53ae Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Mon, 20 Feb 2023 03:34:49 +0100 Subject: [PATCH 1/3] fix --- Parse/Parse/Internal/PFInternalUtils.h | 3 --- Parse/Parse/Internal/PFInternalUtils.m | 19 ------------------- Parse/Parse/Source/Parse.m | 18 +++++++++++++----- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/Parse/Parse/Internal/PFInternalUtils.h b/Parse/Parse/Internal/PFInternalUtils.h index 5a0470879..d8bd49736 100644 --- a/Parse/Parse/Internal/PFInternalUtils.h +++ b/Parse/Parse/Internal/PFInternalUtils.h @@ -19,9 +19,6 @@ @interface PFInternalUtils : NSObject -+ (NSString *)parseServerURLString; -+ (void)setParseServer:(NSString *)server; - /** Clears system time zone cache, gets the name of the time zone and caches it. This method is completely thread-safe. diff --git a/Parse/Parse/Internal/PFInternalUtils.m b/Parse/Parse/Internal/PFInternalUtils.m index 629746974..d8c4cd203 100644 --- a/Parse/Parse/Internal/PFInternalUtils.m +++ b/Parse/Parse/Internal/PFInternalUtils.m @@ -40,27 +40,8 @@ #import "PFProduct.h" #endif -static NSString *parseServer_; - @implementation PFInternalUtils -+ (void)initialize { - if (self == [PFInternalUtils class]) { - [self setParseServer:_ParseDefaultServerURLString]; - } -} - -+ (NSString *)parseServerURLString { - return parseServer_; -} - -// Useful for testing. -// Beware of race conditions if you call setParseServer while something else may be using -// httpClient. -+ (void)setParseServer:(NSString *)server { - parseServer_ = [server copy]; -} - + (NSString *)currentSystemTimeZoneName { static NSLock *methodLock; static dispatch_once_t onceToken; diff --git a/Parse/Parse/Source/Parse.m b/Parse/Parse/Source/Parse.m index d4c2ae765..8fa879236 100644 --- a/Parse/Parse/Source/Parse.m +++ b/Parse/Parse/Source/Parse.m @@ -59,7 +59,6 @@ + (void)setApplicationId:(NSString *)applicationId clientKey:(NSString *)clientK PFParameterAssert(clientKey.length, @"`clientKey` should not be nil."); currentParseConfiguration_.applicationId = applicationId; currentParseConfiguration_.clientKey = clientKey; - currentParseConfiguration_.server = [PFInternalUtils parseServerURLString]; // TODO: (nlutsenko) Clean this up after tests are updated. [self initializeWithConfiguration:currentParseConfiguration_]; @@ -69,13 +68,17 @@ + (void)setApplicationId:(NSString *)applicationId clientKey:(NSString *)clientK } + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration { + PFConsistencyAssert(![self currentConfiguration], @"Parse is already initialized."); + [self initializeWithConfigurationAllowingReinitialize:configuration]; +} + ++ (void)initializeWithConfigurationAllowingReinitialize:(ParseClientConfiguration *)configuration { PFConsistencyAssert(configuration.applicationId.length != 0, @"You must set your configuration's `applicationId` before calling %s!", __PRETTY_FUNCTION__); PFConsistencyAssert(![PFApplication currentApplication].extensionEnvironment || configuration.applicationGroupIdentifier == nil || configuration.containingApplicationBundleIdentifier != nil, @"'containingApplicationBundleIdentifier' must be non-nil in extension environment"); - PFConsistencyAssert(![self currentConfiguration], @"Parse is already initialized."); ParseManager *manager = [[ParseManager alloc] initWithConfiguration:configuration]; [manager startManaging]; @@ -94,11 +97,14 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration { object:nil]; return nil; }]; - } + (void)setServer:(nonnull NSString *)server { - [PFInternalUtils setParseServer:server]; + // Re-initialize SDK + currentParseConfiguration_.applicationId = currentParseManager_.configuration.applicationId; + currentParseConfiguration_.clientKey = currentParseManager_.configuration.clientKey; + currentParseConfiguration_.server = server; + [self initializeWithConfigurationAllowingReinitialize:currentParseConfiguration_]; } + (nullable ParseClientConfiguration *)currentConfiguration { @@ -126,7 +132,9 @@ + (nullable NSString *)getClientKey { } + (nullable NSString *)server { - return [[PFInternalUtils parseServerURLString] copy]; + ParseClientConfiguration *config = currentParseManager_ ? currentParseManager_.configuration + : currentParseConfiguration_; + return currentParseManager_.configuration.server; } ///-------------------------------------- From f445e34188e18ef37956ef380510e53a1cfdbfb6 Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Mon, 20 Feb 2023 03:56:57 +0100 Subject: [PATCH 2/3] fix missing config settings when reinitializing --- Parse/Parse/Source/Parse.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Parse/Parse/Source/Parse.m b/Parse/Parse/Source/Parse.m index 8fa879236..f00c1eed1 100644 --- a/Parse/Parse/Source/Parse.m +++ b/Parse/Parse/Source/Parse.m @@ -100,11 +100,12 @@ + (void)initializeWithConfigurationAllowingReinitialize:(ParseClientConfiguratio } + (void)setServer:(nonnull NSString *)server { + // Use current config with new server + ParseClientConfiguration *config = currentParseManager_ ? currentParseManager_.configuration : currentParseConfiguration_; + config.server = server; + // Re-initialize SDK - currentParseConfiguration_.applicationId = currentParseManager_.configuration.applicationId; - currentParseConfiguration_.clientKey = currentParseManager_.configuration.clientKey; - currentParseConfiguration_.server = server; - [self initializeWithConfigurationAllowingReinitialize:currentParseConfiguration_]; + [self initializeWithConfigurationAllowingReinitialize:config]; } + (nullable ParseClientConfiguration *)currentConfiguration { From 71e6c3976f355087fb2fe22ab14fe49fc68b08cc Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:05:13 +0100 Subject: [PATCH 3/3] update code comment --- Parse/Parse/Source/Parse.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Parse/Parse/Source/Parse.h b/Parse/Parse/Source/Parse.h index 6537b1d91..b7b50a8cf 100644 --- a/Parse/Parse/Source/Parse.h +++ b/Parse/Parse/Source/Parse.h @@ -107,11 +107,13 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable, readonly, class) ParseClientConfiguration *currentConfiguration; /** - Sets the server URL to connect to Parse Server. The local client cache is not cleared. - @discussion This can be used to update the server URL after this client has been initialized, without having to destroy this client. An example use case is - server connection failover, where the clients connects to another URL if the server becomes unreachable at the current URL. - @warning The new server URL must point to a Parse Server that connects to the same database. Otherwise, issues may arise - related to locally cached data or delayed methods such as saveEventually. + Sets the server URL to connect to Parse Server. + @discussion This can be used to update the server URL after the client was initialized. An example use case is server + connection failover, where the client connects to another URL if the server becomes unreachable at the current URL. The + client will be re-initialized maintaining the same configuration. Any pending requests will still be made against the previous + server URL that was set at the time the request was queued. + @warning The new server URL must point to a Parse Server that connects to the same database. Otherwise, issues may + arise related to locally cached data or delayed methods such as saveEventually. @param server The server URL to set. */ + (void)setServer:(nonnull NSString *)server;