Reputation: 2497
Is it possible to set up an app to use multiple parse.com applications. I am trying to figure out a way to reduce my requests/second, and was thinking that if I set up my instant messaging part of my iPhone app with a different parse.com application Id, then I could use them both simultaneously. You have to set the application Id for the project in the appDelegate as follows:
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
Parse.setApplicationId("AppIdString", clientKey: "ClientKeyString")
}
If I put the same Parse.setApplicationId("AppIdString", clientKey: "ClientKeyString")
code in the viewDidLoad method (or somewhere similar) of a particular view controller, will it override the application Id set in the app delegate and allow queries from this view controller to interact with the alternative parse application?
Upvotes: 0
Views: 303
Reputation: 2497
I've been playing with this, and it indeed appears you can, may keep this quiet...
-edit- Explanation: You might think this would cause issues with the query not knowing which application Id to use, however the query uses whichever Application ID was set most recently. You can set an individual Application ID in the viewDidLoad method of every view controller, and any queries carried out in that view controller will use the application ID defined in that view controller.
You can even exploit this by setting multiple application ID's within a single function.
Parse.setApplicationId("appIdString-1", clientKey: "clientKeyString-1")
var query = PFQuery(classname: "classname")
query.getObjectInBackgroundWithId(.....)
Parse.setApplicationId("appIdString-2", clientKey: "clientKeyString-2")
var query2 = PFQuery(classname: "classname2")
query2.getObjectInBackgroundWithId(.....)
This can get quite complicated, so must be handled with care. It is most simple and effective to just have different view controllers with their own application Id.
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
Parse.setApplicationId("mainAppId", clientKey: "mainClientKey")
return true
}
Then in your other view controllers use
override func viewWillDisappear(animated: Bool) {
Parse.setApplicationId("mainAppId", clientKey: "mainClientKey")
println("leabving")
}
override func viewDidLoad() {
super.viewDidLoad()
Parse.setApplicationId("secondAppId", clientKey: "secondClientKey")
}
It is very important to reset the app Id in the viewWillDissapear method so that when you return to the parent viewController (if you're using push segues) queries use the right App Id. Also be aware with what happens when the app enters background. It requires a little effort to make this work error free, but it's definitely worth it.
Upvotes: 1