Thursday, April 29, 2010

Moving forward with customized keyboards in iphone 3.2

I recently inherited a project that had customized iphone keyboards by adding a toolbar following the techniques in http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-custimize-keyboard.html.

Sadly, this code behaves badly in the new SDK 3.2, it crashes. First time because of a index out of bounds, and once that was fixed then an infinite loop on keyboardDidShow. (And yes I did catch the object name change too). Luckily, 3.2 provides a new handy method to simply add the inputAccessoryView with out all the previous fuss.

But, do you want to release just a 3.2 app? If your in my position, the business sponsors do not want to hear that their hard won customized toolbar will only be seen on the iPad for a while. They expect backwards compatibility.

I solved this dilemma by using the UIInputTextField instancesRespondTo inputAccessoryView to guard the call that sets up the keyboard event listeners required in the older solution, so that only on 3.1 devices will the keyboard intercepts be executed. Then I setup a new message type AddToolbar to be called by TextFieldDelegates for fields where the toolbars will be needed.

Note that Apple does not 'publish' the Notification that triggers shouldTextBeginEditing or textFieldDidBeginEditing so instead of just having a global delegate I instead trigger this new AddToolbar notification as part of my TextFieldDelegate response.

The new message listener again checks for inputAccessoryView support and in 3.2 code makes the call to add the new Toolbar.

No comments:

Post a Comment