Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically changing parse server URL in iOS SDK #1390

Closed
nebitrams opened this issue Feb 18, 2019 · 5 comments
Closed

Dynamically changing parse server URL in iOS SDK #1390

nebitrams opened this issue Feb 18, 2019 · 5 comments

Comments

@nebitrams
Copy link

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

  1. Premium: https://abc1.server.com/parse
  2. 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.")
}

@brianyyz
Copy link

brianyyz commented Mar 8, 2019

This question has come up a few times in the past and I don't think there was ever an answer that allowed an app to re-initialize Parse without restarting the app. The solution that I've used to get around this is to externalize the subscription info on a separate route and based on the response initialize Parse with the appropriate server info.

@TomWFox
Copy link
Contributor

TomWFox commented Mar 8, 2019

Could you instead, restrict the activity of ‘basic’ users on the same server as the premium users?

Sent with GitHawk

@TomWFox
Copy link
Contributor

TomWFox commented Mar 8, 2019

This issue has already been discussed in #1209, so could you close this.

@nebitrams
Copy link
Author

Could you instead, restrict the activity of ‘basic’ users on the same server as the premium users?

Sent with GitHawk

Technically it is possible to support both premium and basic on the same server. However, I want to dedicate the CPU power to premium users and re-direct basic users to a lower grade server.

@nebitrams
Copy link
Author

This question has come up a few times in the past and I don't think there was ever an answer that allowed an app to re-initialize Parse without restarting the app. The solution that I've used to get around this is to externalize the subscription info on a separate route and based on the response initialize Parse with the appropriate server info.

Thanks. This is a smart way to achieve the same outcome. This means that I need to "delay" parse initialisation until the app figure out the user category (externalised since I can't use any Parse cloud function for this purpose).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants