Skip to content

Commit fd487da

Browse files
authored
fix: Parse.setServer does not set new server URL (#1708)
1 parent 81b7ddb commit fd487da

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

Parse/Parse/Internal/PFInternalUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
@interface PFInternalUtils : NSObject
2121

22-
+ (NSString *)parseServerURLString;
23-
+ (void)setParseServer:(NSString *)server;
24-
2522
/**
2623
Clears system time zone cache, gets the name of the time zone
2724
and caches it. This method is completely thread-safe.

Parse/Parse/Internal/PFInternalUtils.m

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,8 @@
4040
#import "PFProduct.h"
4141
#endif
4242

43-
static NSString *parseServer_;
44-
4543
@implementation PFInternalUtils
4644

47-
+ (void)initialize {
48-
if (self == [PFInternalUtils class]) {
49-
[self setParseServer:_ParseDefaultServerURLString];
50-
}
51-
}
52-
53-
+ (NSString *)parseServerURLString {
54-
return parseServer_;
55-
}
56-
57-
// Useful for testing.
58-
// Beware of race conditions if you call setParseServer while something else may be using
59-
// httpClient.
60-
+ (void)setParseServer:(NSString *)server {
61-
parseServer_ = [server copy];
62-
}
63-
6445
+ (NSString *)currentSystemTimeZoneName {
6546
static NSLock *methodLock;
6647
static dispatch_once_t onceToken;

Parse/Parse/Source/Parse.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ NS_ASSUME_NONNULL_BEGIN
107107
@property (nonatomic, nullable, readonly, class) ParseClientConfiguration *currentConfiguration;
108108

109109
/**
110-
Sets the server URL to connect to Parse Server. The local client cache is not cleared.
111-
@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
112-
server connection failover, where the clients connects to another URL if the server becomes unreachable at the current URL.
113-
@warning The new server URL must point to a Parse Server that connects to the same database. Otherwise, issues may arise
114-
related to locally cached data or delayed methods such as saveEventually.
110+
Sets the server URL to connect to Parse Server.
111+
@discussion This can be used to update the server URL after the client was initialized. An example use case is server
112+
connection failover, where the client connects to another URL if the server becomes unreachable at the current URL. The
113+
client will be re-initialized maintaining the same configuration. Any pending requests will still be made against the previous
114+
server URL that was set at the time the request was queued.
115+
@warning The new server URL must point to a Parse Server that connects to the same database. Otherwise, issues may
116+
arise related to locally cached data or delayed methods such as saveEventually.
115117
@param server The server URL to set.
116118
*/
117119
+ (void)setServer:(nonnull NSString *)server;

Parse/Parse/Source/Parse.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ + (void)setApplicationId:(NSString *)applicationId clientKey:(NSString *)clientK
5959
PFParameterAssert(clientKey.length, @"`clientKey` should not be nil.");
6060
currentParseConfiguration_.applicationId = applicationId;
6161
currentParseConfiguration_.clientKey = clientKey;
62-
currentParseConfiguration_.server = [PFInternalUtils parseServerURLString]; // TODO: (nlutsenko) Clean this up after tests are updated.
6362

6463
[self initializeWithConfiguration:currentParseConfiguration_];
6564

@@ -69,13 +68,17 @@ + (void)setApplicationId:(NSString *)applicationId clientKey:(NSString *)clientK
6968
}
7069

7170
+ (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration {
71+
PFConsistencyAssert(![self currentConfiguration], @"Parse is already initialized.");
72+
[self initializeWithConfigurationAllowingReinitialize:configuration];
73+
}
74+
75+
+ (void)initializeWithConfigurationAllowingReinitialize:(ParseClientConfiguration *)configuration {
7276
PFConsistencyAssert(configuration.applicationId.length != 0,
7377
@"You must set your configuration's `applicationId` before calling %s!", __PRETTY_FUNCTION__);
7478
PFConsistencyAssert(![PFApplication currentApplication].extensionEnvironment ||
7579
configuration.applicationGroupIdentifier == nil ||
7680
configuration.containingApplicationBundleIdentifier != nil,
7781
@"'containingApplicationBundleIdentifier' must be non-nil in extension environment");
78-
PFConsistencyAssert(![self currentConfiguration], @"Parse is already initialized.");
7982

8083
ParseManager *manager = [[ParseManager alloc] initWithConfiguration:configuration];
8184
[manager startManaging];
@@ -94,11 +97,15 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration {
9497
object:nil];
9598
return nil;
9699
}];
97-
98100
}
99101

100102
+ (void)setServer:(nonnull NSString *)server {
101-
[PFInternalUtils setParseServer:server];
103+
// Use current config with new server
104+
ParseClientConfiguration *config = currentParseManager_ ? currentParseManager_.configuration : currentParseConfiguration_;
105+
config.server = server;
106+
107+
// Re-initialize SDK
108+
[self initializeWithConfigurationAllowingReinitialize:config];
102109
}
103110

104111
+ (nullable ParseClientConfiguration *)currentConfiguration {
@@ -126,7 +133,9 @@ + (nullable NSString *)getClientKey {
126133
}
127134

128135
+ (nullable NSString *)server {
129-
return [[PFInternalUtils parseServerURLString] copy];
136+
ParseClientConfiguration *config = currentParseManager_ ? currentParseManager_.configuration
137+
: currentParseConfiguration_;
138+
return currentParseManager_.configuration.server;
130139
}
131140

132141
///--------------------------------------

0 commit comments

Comments
 (0)