Beware the Lure of the iOS UIWebView

Apple's iOS SDK provides a class, UIWebView, that provides a simple way to display HTML content in an iOS application. Many apps use UIWebView to display web pages, online help, and other formatted content.

For the basic purpose of displaying HTML content, it works pretty well. However, as it appears to just be a wrapper around WebKit, one might be tempted to use it to try to implement a full-fledged web browser embedded in an application. Don't do this! UIWebView has many limitations that make it unsuitable for this purpose:

  • Many commonly used JavaScript functions, such as alert() and window.open(), don't work at all or only work in limited ways in a UIWebView. So many of the web sites one would try to visit do not work in a UIWebView.
  • There are limited hooks for customizing the behavior. There are a few delegate methods that notify your app when the web view starts loading or finishes loading, but you can't detect many of the events you'd really want to detect.
  • UIWebView does not send the same browser identification info that Mobile Safari does, so some servers will treat it as an unknown browser and return limited content.

Of course, some intrepid developers have found ingenious ways to work around some of these limitations. If you really want to try it, or if you are curious about what kinds of hackery are needed to use UIWebView as a web browser, check out these links:

The lesson I learned (after several hours of banging my head against the wall) is to pass web URLs over to Safari, rather than trying to display them in a UIWebView within my app. It's just not the right tool for this job.


Update (2011/10/1): My original post included this bullet point:

  • You can't control authentication. UIWebView can open an HTTPS connection, but if the server-side certificate is self-signed, there is no way to get it to ignore the certificate, and so it just fails with an error message.

I've been informed that this is not entirely true. It is possible to somehow "preconnect" to the server with an NSConnection, deal with authentication, and then pass the credentials to the UIWebView. More information is available here: http://stackoverflow.com/questions/11573164/uiwebview-to-view-self-signe...

My JavaScript Cheatsheet

A couple of times per year, I have to work on something that requires me to write some JavaScript. Because I do it so rarely, I always have to reacquaint myself with the language by skimming through JavaScript: The Good Parts and finding some good online reference documentation.

In an effort to reduce the time needed to do this next time, I'm recording the little things that I ran across that I didn't remember or wished I could have found faster. So this is my own personal refresher for JavaScript. It may not help you at all.

Also see my Node.js Cheatsheet.

Reference Links

(268242) Pebble

My wife has had a minor planet named after her. This is the official naming citation, written by the planet's discoverer, Jim Bedient:

(268242) Pebble = 2005 JW1

Discovered 2005 May 4 by J. Bedient at Haleakala-Faulkes Telescope North.

Pebble Johnson (b. 19xx) is an innovative teacher of middle-school science and technology in Forsyth County, Georgia. She uses astronomy to heighten interest and excitement in the physical sciences among her students.

The naming citation was published in MPC # 75106:
http://www.minorplanetcenter.net/iau/ECS/MPCArchive/2011/MPC_20110517.pdf

Jim also wrote the following in an email::

On May 4, 2005, I was observing with the 2.2m Faulkes Telescope-North on Haleakala, Maui.  While observing an asteroid on the NEO list, I observed another object in the background.  I performed astrometric observations on succeeding nights, and it received the provisional designation 2005 JW1. After following it for several years, its orbit has been accurately determined, and a few months ago it received its permanent designation, (268242). Under International Astronomical Union rules, this made it eligible for naming, and of the privileges of discovering a minor planet is naming it. A couple of months ago I submitted a name proposal to the IAU's Working Group for Small Body Nomenclature. Last week I was informed that the proposed name had been approved, and it is hereafter known as (268242) Pebble, in honor of my good friend Dr. Pebble Johnson.

...

With the boom in minor planet discoveries in the last decade, due the advent of more sophisticated techniques, particularly larger telescopes and electronic detectors, naming citations are required to be considerably briefer than they once were allowed to be.  I really couldn't wax poetic about meeting Pebble ten years ago at Dr. Karen Meech's TOPS workshops in Hawaii, how she became a very dear friend, how I helped with her Ph.D thesis, and all the things, small and large, that go into forming a strong friendship. Placing her name in perpetuity on this small piece of solar system real estate is just an insignificant monument to a person with a very large heart.  I am honored to know her and to be able to make this gesture.

Do We Still Need Programmers?

When reading descriptions of how software is produced, I often wonder what role programmers play. Programmers used to be the people who made software, but now a lot of other people are involved and claim credit for doing the work.

There has to be an "architect" who guides the overall structure of the system. Often architects are former programmers, but they are far too important to write any code anymore.

Then there is the "user experience" designer, who decides how the software should interact with its users. We used to call this "user interface design", but the UX people have redefined UI design to be the monkeywork of laying out controls and fields on forms. Programmers can't be trusted with any important design decisions.

There is the database administrator (DBA), who ensures that the programmers can't screw up the database schema.

There are testers who tell the programmers whether they have done their jobs well enough.

With all these other people making the important decisions, what does a programmer do? Apparently programmers are glorified typists who transcribe specifications written by architects and UX designers into code that is verified by testers.

Of course, that's not how things are.

While there are teams and organizations that operate as described above, a lot of software is created by solitary programmers. The boss says "We need feature X," and a programmer then designs the user experience, updates the database schema, implements the new functionality, tests it, creates some new icons in Photoshop, adds a couple of pages to the user manual, and deploys the new software to the customer.

Somehow a programmer is able to do this without help from all those people who are too important to write code.

Those other people aren't useless. Software is certainly better when a good architect and good DBA maintain its structure, and when a talented UX designer makes it easy to use, and when good testers find the problems. But software is still made by programmers. Those other people don't make software—they make wishes.

UTF-8

Matt Gallagher's "User interface strings in Cocoa" post is good for its overall purpose (telling people how to use NSLocalizedString()), but I especially like this little embedded rant:

A quick swipe at almost everybody: UTF-8 has been around since 1993 and Unicode 2.0 since 1996; if you have created any 8-bit character content since 1996 in anything other than UTF-8, then I hate you.

I weep to think of the years of programmer time that are still wasted attempting to support non-Unicode formats without characters getting garbled because people are still creating content using ancient encodings without useful identifiers to indicate what nonsense encoding they're using (or worse, people creating content that explicitly uses the wrong encoding for an encoding-specific text field).

MacRoman? Atrocious. Big-5? I hope you want to see garbage output. Windows Latin? You suck. If you're creating new content using anything other than UTF-8, UTF-16 or UTF-32 then you should be forced to serve prison time with whatever idiot monkey decided that UTF-16 should be allowed little-endian and big-endian variants instead of a single authoritative encoding.

Yeah, seriously. If you call yourself a programmer, but you don't understand what all this Unicode, UTF-8, and UTF-16 business is about, please read Joel Spolsky's The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).

The Apple Store Needs a Checkout Counter

The Apple Store is a great place to go if you want to play with new Apple products or get help at the Genius Bar. But if you go there to buy something, the experience is confusing and humiliating.

Everyone knows how the process of buying something at a store is supposed to work:

  1. You pick up the product(s) you want to buy.
  2. You go to the end of the line at the checkout counter.
  3. When it's your turn, you step up to the counter, transact your business, and go on your way.

In contrast, here is how things work at the Apple Store:

  1. You pick up the product(s) you want to buy.
  2. You stand there like a child who has lost his mommy, looking around for a friendly Apple associate who can help you.
  3. As the Apple associates are always busy helping other customers, you pick one and stand nearby, hoping to catch their attention when they are finished with the current customer.
  4. Eventually, after helping the current customer, and maybe a few others who are also standing nearby, the associate asks how they can help you. You say you want to buy the things you have been holding. The associate says, "OK, I'll find someone to help you", and goes to look for one of the associates who has one of the magic credit-card-reading devices. You stand there looking lost again for a while.
  5. Eventually, a person with a magic device arrives to let you make your purchase. You fumble around, juggling products between your armpits, your crotch, and under your chin while you present each item for scanning. Then you drop all the items while you dig out your wallet and credit card.
  6. While you pick up the items you have dropped, the person swipes your card, then hands the little device back to you so you can check some boxes and sign your name. Again, your items have to go into your armpits and onto the floor.
  7. While you pick up your items again, the person goes to one corner of the store to get your printed receipt, then to the opposite corner of the store to get you a bag, then back to you. You help the associate put your items into the bag, and then you go on your way.

Wouldn't this all be easier if there was a checkout counter?

Sometimes the old ways are best.

What I've Learned about iOS Development

I've been playing around with development for Mac OS X and iOS for a few years. I've had a pretty good grasp of how Cocoa and UIKit worked, and I've written some simple apps, but for the past month I've been working on my first Real iOS Application. I've had to solve some problems that were easily ignored when writing little apps for fun. What follows is a randomly ordered collection of some of the little techniques and tips I didn't know before, which may be useful for other Cocoa newbies.

App Idea: Prose Translation Assistant

(This is just an idea. As I explain my post about Why I Loved The Social Network, I think ideas are cheap, so if you want to "steal" this idea and make the app, I heartily support you.)

A friend has started a personal project to translate the works of Jules Verne from the original French into English, as he is dissatisfied with the existing English translations. He is going about it pretty much the way I would: he has a browser window open with the original French text, a browser window with Google Translate, and a text editor where he is writing the English translation. He also has a French-English dictionary on hand.

I wondered whether there might be some software available that is specifically designed for this purpose. Some Googling finds plenty of applications to assist in translation, but all the ones I found are designed to help translate conversations, e-mails, or other such things. I couldn't find anything designed for assisting with translating a novel, play, or other such work, where the translation needs to be written by a human in an accurate-but-artful way.

It got me thinking about how I would design an application to assist with this process, making it less necessary to switch between various applications and documents.

Why I Loved The Social Network

I'm writing this the night before the Oscars, but that is not why I'm writing. I only saw three of the films nominated for Best Picture: The King's Speech, True Grit, and The Social Network. While I enjoyed The King's Speech and True Grit,, I haven't thought about them since I saw them. In contrast, I still think about The Social Network every day.

For some, The Social Network is just a story about how an arrogant jerk became a billionaire by screwing over his friends and business associates. I didn't see it that way. To me, it is a story about the nature of creativity and invention.

Setting Up for Use of Microsoft Symbol Server

When debugging native Win32 code, it is useful to have the debug symbols for all of Microsoft's DLLs. The easiest way to set this up is to just set an environment variable before starting Visual Studio (or other Microsoft debugging tools):

set _NT_SYMBOL_PATH=srv*c:\symbols*http://msdl.microsoft.com/download/symbols

The first time you run the debugger after setting this, it will take some time to start as it downloads symbol files from the Internet into your local symbol cache, but it will be faster after that. Whenever you update your system with patches or service packs, the new symbols will automatically be downloaded the next time you debug.

For more information, see these pages:

(This post is really for my own benefit. I have trouble finding this information whenever I set up a new development workstation, so I'm putting it somewhere I'll know to look.)

Syndicate content