Description
Can iOS app switch between 2 parse-server dynamically without restarting the iOS App?
My usage scenario is as follows...
Currently my iOS App connects to parse-server on Heroku. I am planning to split my users into two groups: premium and basic. I have prepared two servers
- Premium:
https://abc1.server.com/parse
- Basic:
https://abc2.server.com/parse
I need to implement the logic to make to App connect to one of the two servers depending on the logon user profile. The app retrieves the logon user profile from the current parse-server and decide whether there is a need to switch to another server. Both servers point to the same database.
I had implemented the following logic and it works. However, it requires a force App restart because ParseClientConfiguration is initialised in the AppDelegate application:didFinishLaunchingWithOptions function. Can the app re-point to another parse-server without restarting the App?
Sample code to determine server URL.
if (User.Instance.IsPremium()) {
let config = ParseClientConfiguration { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "abc"
ParseMutableClientConfiguration.clientKey = "def"
ParseMutableClientConfiguration.server = "https://abc1.server.com/parse"
}
Parse.initialize(with: config)
} else {
let config = ParseClientConfiguration { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "abc"
ParseMutableClientConfiguration.clientKey = "def"
ParseMutableClientConfiguration.server = "https://abc2.server.com/parse"
}
Parse.initialize(with: config)
}
In my primary view controller, I added a restart app logic.
if (isServerURLChanged()) {
DisplayMessage(title:"App Restarting", message:"App restarting to switch to Premium/Free tier.")
}