1

i am doing a asynchronous request, and I'm wondering if there is no internet on the iPhone how would i handle it instead of the app just crashing.

Error: 'NSInvalidArgumentException', reason: 'data parameter is nil'

farhan
  • 335
  • 2
  • 13

2 Answers2

0

I would suggest you to check your internet connection before making request to server for data. You can user Reachability class to ensure the same.

Devang Tandel
  • 2,988
  • 1
  • 21
  • 43
0

You can handle it by performing various pre-cautious things as follows:

  1. Check for the internet connection, in case making a call to server. But it will not save you in all conditions, as there might be an issues on the server side due to server errors or coding errors.

  2. You can check for NULL at places where you can expect NULL data and handle it.

  3. I am giving you my sample MACRO, i am using frequently to avoid crashes due to NULL values.

#define VALIDATE_NULL(str) ([str length] > 0) ? str : @""

You can use this macro freely anywhere on NSString values. Enjoy. :)

Vinay Jain
  • 2,644
  • 3
  • 26
  • 44