September 11 retrospective

The last thing the internet needs is yet another commentary about September 11, so I will be brief.

I used to listen to sports radio. A lot. Especially when I lived in Safety Harbor, Florida.

It seemed like just another Tuesday morning drive to the office down in St. Petersburg. Tony Bruno was on the air yakking about something or the other, who can remember what. I pull into the First Union parking lot at around 10 minutes until 9 or so, and Tony is making some kind of comment about a fire in a skyscraper in New York.

Cross the street, quick elevator ride up to the 6th floor, and there is dead silence amongst my team. When it was clear what was happening, my first thought was that my wife worked on the 29th floor of a building in downtown Tampa, which thankfully was evacuated very quickly.

The comic relief that morning was provided by Jim, our company president who was scheduled to fly out of town on business that morning. He called me at the office from his cell phone as he was waiting in traffic trying to get to the Tampa airport, asking me what was going on. (I am not sure what Jim listens to while driving, apparently nothing.) I told him to turn around and head back home.

Much like everyone else on that day, we followed along with the news at the office until the internet was overwhelmed with traffic, at which point we switched over to radio. I tried to keep everyone focused to try and get something done, but it was a lost cause and we closed the office a few hours early.

The air travel experience was much different when I traveled to my brother’s wedding 10 days later. My wife also had a plane ticket but would not go with me, and I could not blame her. Are we better or worse off in this country after the events that occurred on that day? I am not sure how to answer that, so I will leave it up to posterity.

But I will tell you to make sure to hug family and friends today to remind them how much they are appreciated.

We must not fear.

We must not forget.

How to make random entries into the iPhone address book

Are you a frustrated iOS developer working on an app that has to access the built-in address book on the device? Frustrated because you can’t find sample data to populate the address book in your Simulator, and you are too busy to create a bunch of test data?

Well, for a limited time* only, we at the Do Something Here Labs have a deal for you. For just a minimal** postage and handling charge, you too can use this sample code below to create random entries to your hearts content in your very own iOS app.

Here is the code in question. Simply drop this method into your Objective-C source code and call it in your app, and you will soon have contacts, contacts, and more contacts.


- (void)addressBookData
#define GENDER_OF_NAMES             @"m"    // use m for male or f for female
#define URL_FORMAT  @""
    NSString *urlString = [NSString stringWithFormat:URL_FORMAT, GENDER_OF_NAMES, NUMBER_OF_RANDOM_ENTRIES];
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    NSString *stringData = [NSString stringWithUTF8String:[data bytes]];
    NSString *areaCode = [NSString stringWithFormat:@"%03d", (arc4random() % 799 + 200)];
    NSArray *lineArray = [stringData componentsSeparatedByString:@"\n"];
    for (NSString *line in lineArray)
        if ([line length] > 0)
            NSArray *fieldArray = [line componentsSeparatedByString:@","];
            if ([fieldArray count] == 3)
                ABAddressBookRef addressBook = ABAddressBookCreate(); 
                ABRecordRef person = ABPersonCreate();
                NSString *phone = [NSString stringWithFormat:@"%@-%03d-%04d", areaCode,
                                   (arc4random() % 799 + 200), (arc4random() % 9999)];   
                ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
                CFStringRef phoneType = (arc4random() % 2 == 0 ? kABPersonPhoneMainLabel : kABPersonPhoneMobileLabel);
                ABMultiValueAddValueAndLabel(phoneNumberMultiValue, phone, phoneType, NULL);
                ABRecordSetValue(person, kABPersonFirstNameProperty, [fieldArray objectAtIndex:1], nil);
                ABRecordSetValue(person, kABPersonLastNameProperty, [fieldArray objectAtIndex:2], nil);
                ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
                ABAddressBookAddRecord(addressBook, person, nil);
                ABAddressBookSave(addressBook, nil);
                NSLog(@"Created record for %@ %@ (%@: %@)", [fieldArray objectAtIndex:1], 
                      [fieldArray objectAtIndex:2], phoneType, phone);
    NSLog(@"Done creating address book data.");

On a housekeeping note, make sure to include the AddressBook.framework library in your application, and make sure to import the AddressBook.h header file as shown. Although if you are already developing an app that accesses the address book, you probably have this covered.

Also, your device or computer needs to have internet access while the code is running, as the code accesses a simple PHP application that I did a while back to do random sports roster generation. (The PHP application will generate a maximum of 99 entries at a time, so if you want to try and have it generate 42 billion names with one call, go right on ahead and try.) OK, I probably should not be blocking the main thread with the synchronous request, but I did not have time do something other than the most quick and dirty solution possible.

But wait, there’s more.

Happy birthday to Terry Bradshaw. I’m sure that if Terry was developing an iOS app, and he needed to populate some random address book entries, this would be the code he would use. And if it is good enough for Terry, isn’t it good enough for everyone?

(* = For as long as this web site is accessible on the internet)

(** = $0.00)

Batter vs. Pitcher Lite now available

Maybe someone at Apple was reading my blog yesterday, because a couple of hours after I posted my lamentations over the BvP Lite approval wait, the app went into the approval process and was approved then an hour or so after that. Awesome job Apple, thanks.

Here is the link to the Batter vs. Pitcher Lite free app:

Batter vs. Pitcher Lite

No birthday, anniversary, or holiday wishes at this time, but I would like to say that I am totally impressed with my new 13″ MacBook Air. It seems to be more than adequate for building iOS apps, and due to the SSD drive, it actually seems to compile, build, and fire up the simulator much faster than my old MacBook Pro.