Apr 052011
 

I have an application that reads data from a JSON file and displays the locations for the records it’s reading in a map. Fairly standard fare and all works well. Well, it worked on an iPhone, but on an iPad the application would crash after loading a few hundred records. I thought there might be something wrong with the names of the locations that I was loading. These would be the titles for the annotations, so having established that a particular record was giving trouble I just disregarded it and moved on. Then I got a new data set and the problem went away. At least the problem with that record went away, but now a different record caused a problem, and again only on the iPad. I just buried my head in the sand. I’m not worried about the app running on an iPad so it’s not a major problem.

Except then I got a new iPhone, still an iPhone 4, so exactly the same model as the old one. And now the application crashes on the new iPhone just like it did on the iPad, but it doesn’t crash on the old iPhone. And now I am worried, because if it works on some iPhones and not on others that’s not a good thing. So I looked at the differences between the two iPhones. Aha! The new one runs iOS 4.3.1 and the old one runs 4.1. And the iPad runs 4.3.1 too, so that’s interesting.

But there has to be a root cause, because by ignoring some data records I could get the problem to stop happening. So this time I looked closer at the data and found the problem. The latitude and longitude are included in my data and these are a number of degrees. These range from -360 to +360 and have 5 or 6 decimal places. Except the bad records, which had been badly entered into the data file and had no decimal point, so they read as 3 million degrees or something.

Earlier versions of iOS would probably replace the bad values with zero, while 4.3 and later would crash. In fact the crash was very low down in the OS, it would make my app so it would not run again, I’d have to reboot the device.

I changed my app so it replaced these erroneous coordinates with zeroes and now my app runs perfectly. OK there are some annotations placed at the north pole, but that’s a data issue and nothing to do with my app. I just need to get the data cleaned up.

There are some lessons here: Never trust the data. Never ignore an error, and test for every type of hardware.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.