Archive for November 2014

CLGeocoder with built-in NSCache

In case you were wondering, Apple “recommends” that you only make one call per minute to their geocoding system. I can kind of understand the reasoning behind this, as they do not want to let people abuse the system. If you have a bunch of geocoding requests that you need to make within a short amount of time, you will not be cut off immediately if you push through a bunch of requests within seconds, but eventually you will get clipped. Now, if the requests you make are part of a table view that is scrolling, wouldn’t it be neat if you could find a CLGeocoder with built-in NSCache?

Well now you can. Please check out my GitHub repository for BPGeocoder:

https://github.com/Wave39/BPGeocoder

This class inherits from CLGeocoder and you use it as a replacement for CLGeocoder, except that it maintains its own NSCache of addresses that it has geocoded, and if you pass in an address it has already seen, it does not bother contacting the Apple servers, it just returns back the cached results it found earlier.

BTW, Happy Birthday to Terry Farrell, who played Valerie in Back To School and Lt. Dax on Star Trek: Deep Space 9, which was the best Star Trek series, IMHO. (Additionally, I think we need to get an internet campaign going to get IMDb to change the cast photo on their DS9 page to be one with Terry. Leave a comment if you agree. Sorry, Nicole!)

EXC_BAD_ACCESS when creating Address Book records on iOS

I have this code in one of my apps that creates some test records in the Contacts app, so that I can quickly build up some address book data for testing purposes. However, I just uncommented out this code for the first time in a long time, and now I am getting some kind of object release EXC_BAD_ACCESS exception when creating Address Book records on newer versions of iOS.

I tracked the problem down to this line:

ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);

While this used to work just fine, I needed to change it to this line:

ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);

And now my address book records are created without any kind of memory crash.

BTW, Happy Anniversary to Godzilla, who premiered in Japanese theaters on this day 60 years ago. Additional BTW, for U.S. readers, don’t forget to get out and vote tomorrow.