From a6517645b2a786bb96a3c14aa9ef8df1d7e2ae6a Mon Sep 17 00:00:00 2001 From: Manuel Trezza Date: Wed, 30 Oct 2019 03:48:01 +0100 Subject: [PATCH 1/3] add server property and setServer --- Parse/Parse/Parse.h | 13 +++++++++++++ Parse/Parse/Parse.m | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/Parse/Parse/Parse.h b/Parse/Parse/Parse.h index 8f11dab62..05b32fc2c 100644 --- a/Parse/Parse/Parse.h +++ b/Parse/Parse/Parse.h @@ -106,6 +106,14 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, nullable, readonly, class) ParseClientConfiguration *currentConfiguration; +/** + Sets the server URL to connect to Parse Server. This can be used to update the server URL after this client has been + initialized, without having to destroy this client. + + @param server The server URL to set. + */ ++ (void)setServer:(nonnull NSString *)server; + /** The current application id that was used to configure Parse framework. */ @@ -120,6 +128,11 @@ NS_ASSUME_NONNULL_BEGIN + (nullable NSString *)getClientKey PARSE_DEPRECATED("Use clientKey property."); +/** + The current server URL to connect to Parse Server. + */ +@property (nonatomic, nullable, readonly, class) NSString *server; + ///-------------------------------------- #pragma mark - Enabling Local Datastore ///-------------------------------------- diff --git a/Parse/Parse/Parse.m b/Parse/Parse/Parse.m index 9f84aed79..38367c693 100644 --- a/Parse/Parse/Parse.m +++ b/Parse/Parse/Parse.m @@ -89,6 +89,11 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration { [[self parseModulesCollection] parseDidInitializeWithApplicationId:configuration.applicationId clientKey:configuration.clientKey]; } ++ (void)setServer:(nonnull NSString *)server { + PFConsistencyAssert([self currentConfiguration], @"Parse is not initialized."); + [PFInternalUtils setParseServer:[server copy]]; +} + + (nullable ParseClientConfiguration *)currentConfiguration { return currentParseManager_.configuration; } @@ -113,6 +118,10 @@ + (nullable NSString *)getClientKey { return [self clientKey]; } ++ (nullable NSString *)server { + return [[PFInternalUtils parseServerURLString] copy]; +} + ///-------------------------------------- #pragma mark - Extensions Data Sharing ///-------------------------------------- From 1c97007956739d9a5eb615bfaae80d37fad0f601 Mon Sep 17 00:00:00 2001 From: Manuel Trezza Date: Wed, 30 Oct 2019 03:52:54 +0100 Subject: [PATCH 2/3] removed unnecessary exception when setting server before client is initialized --- Parse/Parse/Parse.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Parse/Parse/Parse.m b/Parse/Parse/Parse.m index 38367c693..3ba063247 100644 --- a/Parse/Parse/Parse.m +++ b/Parse/Parse/Parse.m @@ -90,8 +90,7 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration { } + (void)setServer:(nonnull NSString *)server { - PFConsistencyAssert([self currentConfiguration], @"Parse is not initialized."); - [PFInternalUtils setParseServer:[server copy]]; + [PFInternalUtils setParseServer:server]; } + (nullable ParseClientConfiguration *)currentConfiguration { From 801d856cfa9152b4fe3675abe685b255f7333071 Mon Sep 17 00:00:00 2001 From: Manuel Trezza Date: Mon, 25 Nov 2019 03:38:14 +0100 Subject: [PATCH 3/3] amended docs --- Parse/Parse/Parse.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Parse/Parse/Parse.h b/Parse/Parse/Parse.h index 05b32fc2c..52e76fa1d 100644 --- a/Parse/Parse/Parse.h +++ b/Parse/Parse/Parse.h @@ -107,9 +107,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable, readonly, class) ParseClientConfiguration *currentConfiguration; /** - Sets the server URL to connect to Parse Server. This can be used to update the server URL after this client has been - initialized, without having to destroy this client. - + 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. @param server The server URL to set. */ + (void)setServer:(nonnull NSString *)server;