iOS - Crash after first login

63 views
Skip to first unread message

Andrea Pavan

unread,
Nov 19, 2016, 1:40:52 PM11/19/16
to BaasBox
Hi,
as the object suggest, I'm using BaasBox into an app and I cannot understand why the first login call crash on my device.
I'm using the v. 1.0.0-M3-20160325.

I'm using Swift 3 and initially I used the SDK call for login. This is my code:

This si the test with SDK function:
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?

Luca Cardelli

unread,
Nov 23, 2016, 10:42:02 AM11/23/16
to BaasBox
Hi Andrea,

I can reproduce your errors: seems

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

seems like this errors occurs when you do not setup baasbox correctly in your AppDelegate:

BaasBox.setBaseURL("http://localhost:9000", appCode: "1234567890")


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

Andrea Pavan

unread,
Dec 15, 2016, 6:08:55 AM12/15/16
to BaasBox
Hi thanks for the response.
I solved my problem. The issue was due to an instance variable created before the BaasBox initialiser:

BaasBox.setBaseURL("http://localhost:9000", appCode: "1234567890")

So the instance variable initialise BaasBox without the BaseURL and AppCode and consequently the first call generate a crash due to nil value on BaseURL
Reply all
Reply to author
Forward
0 new messages