Hello. I'm Aleksandar Vacić, professional web developer and wine maker in the making.
Learn more about me or see what I can do for you.

My work & services

Archive for the 'Programming' category

Always use isEqualToString for string comparisons

While working on my iPhone app Quickie, I encountered one of many examples why you must always check your code on the actual device.

Quickie uses Core Data for storage and in one particular place I was comparing the NSString variable to a NSString–typed property of my CoreData class, QuickieList. Like this:

OBJC:
  1. if (QuickieList.listName != theListName)

listName is defined as NSString and theListName is obviously that as well. In this particular instance, both of those had the value of “test”.
In the iPhone Simulator (running on 10.6.2) this comparison returned false, but on the iPhone running 3.1.2 it returned true. When changed into:

OBJC:
  1. if (![QuickieList.listName isEqualToString:theListName])

result was the same.

Never – I repeat — never assume that simulator testing will be fine, even for seemingly small things. It can bite you when you least expect it.

UITextField.text is not always there

If you have UITextField on the page and you need to validate is there something in it (so if yes you can save the input or something), you might do something like this:

OBJC:
  1. if (![addNewCellTextField.text isEqualToString:@""]) {
  2. }

However, this will fail if the field is never touched. That is, until your user taps the field and it gets focus, UITextField.text is nil. Which means that condition above yields true, which is not what you want.
Once it is touched though, this becomes an instance of NSString with value of @””. Thus, always use:

OBJC:
  1. if (addNewCellTextField.text != nil && ![addNewCellTextField.text isEqualToString:@""]) {
  2. }

Watch out for this little trap hole.

How to find crash logs for iPhone applications on Mac, Vista and XP

iTunesConnect service — a web site that iPhone developers use to manage their published applications — has a separate area that will list all the synced crash reports from the application users.

However, not all of the crashes appear there, or are slow to appear. Thus, if you have a desperate problem with someone’s application, it’s a good idea to pick these up and send them to a developer.

Here’s how, in three major operations systems: Mac OS X, Windows Vista / Windows 7 and for Windows XP.

iTunes sync

Application crash logs are transfered to your computer each time you do a sync with the device, in the iTunes. Thus, first step is to sync with iTunes:

Sync the iPhone or iPod Touch through iTunes

Sync the iPhone or iPod Touch through iTunes

Mac OS X

On the Mac, crash logs are kept at:

~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>

where ~ is your Home folder. Here’s an example:

Crash logs on the Mac OS X. Device name is "iPhone AV" here

Crash logs on the Mac OS X. Device name is “iPhone AV” here

There’s the .crash file and .plist file — archive them both and send to a developer. Actually, pick all the files you find there that have the name of the problematic application.

Windows Vista / Windows 7

Files are located here:

C:\Users\<USERNAME>\AppData\Roaming\Apple computer\Logs\CrashReporter/MobileDevice/<DEVICE_NAME>

AppData folder is hidden by default, so here’s how to access it. Get into your personal folder:

User folder, with Vista folder path

User folder, with Vista folder path

Now click on the folder (address) bar which will change the display into Windows folder path and add \AppData to it, then click Enter.

When clicked, the address bar changes into regular Windows folder path

When clicked, the address bar changes into regular Windows folder path

This will then show the folder contents. From here, you can follow the path above until you get to the crash logs.

For Windows 7, follow the same procedure.

Windows XP

Location is here:

C:\Documents and Settings\<USERNAME>\Application Data\Apple computer\Logs\CrashReporter/<DEVICE_NAME>

<USERNAME> is your login username. Application Data folder is usually hidden by default, so you need to reveal it in the same way as in Vista — by typing in and pressing Enter.

And that’s it. Easy :) — rest is for developer to sweat it.

Howto: find UDID of the iPhone or iPod Touch

Easiest way is to get it through iTunes.

On the main device screen, click on the serial number (the blured area below):
iphone-serial

When you click on it, it will change into this screen, which has the UDID:

iphone-uuid

Now do Cmd+C (Mac) or Ctrl+C (Win) — or use menu Edit/Copy — to get it into clipboard.

Using existing iPhone apps

If you have an iTunes Store account, get the free Ad Hoc Helper application. You need to have an email account setup so you can send the UDID to whom ever it’s needed.

The same thing can be done with iStat app, which is not free and it’s main purpose is not to get the UDID. But it does displays it and also allows you to send it over email.

Using backups

On Mac, iPhone backups are at:

/Users/{USERNAME}/Library/Application Support/MobileSync/Backup/{UDID}

On Windows Vista, iPhone backups are located at:

C:\Users\{USERNAME}\AppData\Roaming\Apple Computer\MobileSync\Backup\{UDID}

On Windows XP/2003 it’s:

C:\Documents and Settings\{USERNAME}\Application Data\Apple Computer\MobileSync\Backup\{UDID}

Using iPhone Configuration Utility

On the iPhone Enterprise page at Apple’s site, you can find links to Mac and Windows versions of this utility. One of the things it does is allows you to get the UDID.

Once you connect the device, this is the place to get it:

iphone-config-util

Now just select the identifier and copy into clipboard.

Protected posts?

As I’m baby stepping through the iPhone SDK development, I encounter some strange stuff. Given the unfortunate (to say the least) circumstance of the NDA still in place as of this writing, I can’t post publicly about it. I can’t ask on forums nor would anyone be allowed to answer. That’s how NDA stuff works.

In order not to lose these stuff and to keep note of problem and solution (if I find one) for future benefit, I’m doing this password-protected posts that I will reveal once NDA is lifted.

Which hopefully will happen’ at some point.

update: it did not take long — just days after I did this, Apple killed the NDA.

Tags or categories or topics...