func loginWith(_ email: String, password: String) {
SwiftSpinner.setTitleFont(UIFont(name: "DIN-Light", size: 22.0))
SwiftSpinner.show(duration: 10, title: "Connecting to server...")
client!.authenticateUser(username, password: password, completion: { (success, error) in
if (success) {
debugPrint("Logged in with user: ", username)
} else {
let alert = UIAlertController(title: "Attention", message: "Incorrect Email or Password", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil))
SwiftSpinner.hide()
self.present(alert, animated: true, completion: nil)
}
})
}The result after the first call (the app is started for the first time in device):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
This si the test with REST login call:
func loginWith(_ username: String, password: String) {
SwiftSpinner.setTitleFont(UIFont(name: "DIN-Light", size: 22.0))
SwiftSpinner.show(duration: 10, title: "Connecting to server...")
client!.postPath("/login", parameters: ["username": username, "password": password, "appcode": kBackendAppCode], success: { (responseObject) in
}, failure: { (error) in
debugPrint("error: ", error?.localizedDescription)
})
}The result after the first call (the app is started for the first time in device):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
If I restart the app and try another login, the same login request works perfectly.
How can I solve this issue?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
but since the problem only occurs when you first start the app, it seems a rare bug that I also found myself in an old app.
Looks like your url and appcode are not set properly on first launch, if you try to start the app, close it and then reopen and login it should login without errors.
If this is your error there is a quick fix:
( NOTE : This is not a "Good" fix )
In the BAAClient.m file on line 161 there is the - (id) init { function change:
_baseURL = [NSURL URLWithString:[BaasBox baseURL]];
to
_baseURL = [NSURL URLWithString:@"http://yoururl.com:9000"];
and
_appCode = [BaasBox appCode];
to
_appCode = @"your appcode";
This should set your url and appcode regardless of where you call Baasbox.setup
I'm looking forward to find a better solution to this error.
In the meantime there is a fix.
Let me know if it helps you
Luca