Skip to content

Dynamically changing parse server URL in iOS SDK #1390

Closed

Description

@nebitrams

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.")
}

Activity

  1. brianyyz commented on Mar 8, 2019

    @brianyyz

    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.

  2. TomWFox commented on Mar 8, 2019

    @TomWFox
    Contributor

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

    Sent with GitHawk

  3. TomWFox commented on Mar 8, 2019

    @TomWFox
    Contributor

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

  4. nebitrams commented on Mar 9, 2019

    @nebitrams
    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.

  5. nebitrams commented on Mar 9, 2019

    @nebitrams
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions