How to Know When Apple Finally Gets iCloud Right [#iosdev #icloud]

Gus Mueller of Flying Meat Software offers his opinions on what Apple must do to get iCloud right for developers:

The Shape of Everything: How to Know When Apple Finally Gets iCloud Right

But how are we going to know Apple has finally fixed iCloud syncing for developers and is really serious this time? And I’m not just talking about Core Data syncing, I’m also talking about the APIs developers are given to push document data back and forth. The broken stuff, the things developers laugh at Apple about and have given up on.

Free iPhone Design Templates for Keynote and PowerPoint

Free iPhone Keynote and PowerPoint templates help get you from thought to finish:

Mockapp.com has created both Keynote and PowerPoint templates of iPhone UI elements, and has made them available as free downloads. Say you had a dream in the middle of the night about the most awesome iPhone app that, to your surprise, no one has thought of yet. Instead of waking up in a deep sweat and scribbling said ideas on paper, you could dream them up on Keynote.

After mapping out your concept on Keynote, you could then pitch it to others in a Keynote presentation. The Keynote and PowerPoint templates include alerts, the iPhone keyboard, arrow icons, buttons, as well as a host of other UI elements.

Methods of iPad Detection in Web Applications

With all this Dashcode and iPhone web development exploration that I’ve been doing lately, the question of course came up in my mind… what about the iPad? I’m already using some rudimentary sniffing to make sure iPhone users go to the appropriate spot, but obviously this case would have to be dealt with too, since maybe I would not want to send iPad users to the same spot as the iPhone users.

So I was very glad to find this article: iPad web development tips by Nicholas C. Zakas at his site, NCZOnline.

As it turns out, my method would have failed in that case since I have only been checking for “iPhone” (NOTE: strings are split on multiple lines to fit on this page… they actually don’t have line breaks.):

User-agent string

The previously-linked post describes the iPad Safari user-agent to be in the following format:

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) 
AppleWebKit/531.21.10 (KHTML, like Gecko) 
Version/4.0.4 Mobile/7B334b Safari/531.21.10

This was the user-agent string during the beta testing phase. The format is slightly different for the final release: Although this appears to be the official user-agent string, I have received reports of a user-agent like this:

Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) 
AppleWebKit/531.21.10 (KHTML, like Gecko) 
Version/4.0.4 Mobile/7B314 Safari/531.21.10

You’ll note the addition of “iPhone” in the operating system segment of the user-agent string. This brings the user-agent string for Safari on the iPad more into line with Safari on the iPhone and iPod Touch, which have the following user-agent strings, respectively:

Mozilla/5.0 (iPod; U; CPU iPhone OS 3_0 like Mac OS X; en-us) 
AppleWebKit/528.18 (KHTML, like Gecko) 
Version/4.0 Mobile/7A341 Safari/528.16

Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) 
AppleWebKit/528.18 (KHTML, like Gecko) 
Version/4.0 Mobile/7A341 Safari/528.16

This means a single user-agent string sniff for “iPhone” returns true in all three cases. The problem, of course, is that you might want to serve different experiences to the iPhone/iPod Touch than you would for the iPad. Make sure you double-check any user-agent sniffing designed to target these devices.

Then we move on to the interesting tidbit for the client-side. If detection is necessary, evidently we can use the navigator.platform property:

JavaScript iPad detection

If you’re trying to detect the iPad using JavaScript, there’s a very simple way to do so: check navigator.platform. The value of navigator.platform is always “iPad” when Safari for iPad is the user-agent. This follows the tradition of “iPhone” for the iPhone and “iPod” for the iPod Touch. This is the most accurate way to detect the iPad from JavaScript, assuming you don’t want to do a full user-agent string sniff.

function isIPad() {
    return navigator.platform == "iPad";
}

Also, keep in mind that navigator.platform doesn’t change even when the user-agent string for a browser is changed.

Good information for both sides of the computing fence, so I’m glad to have it!

When JavaScript Conventions Aren’t Conventions

In experimenting with Dashcode last night using the introductory tutorial provided by Apple, I noticed that in their example, they build a URL dynamically:

var dsource = dashcode.getDataSource("list");
var name = dsource.selection().valueForKey("name");
document.location =
    ("http://www.google.com/search?client=googlet&q="
    + name);

But your first thought when looking at this may be (as was mine), “what if there are spaces or other characters in the “name” value that are not legal in an URL?

So then I set out to use one of the standard functions for escaping URIs: encodeURIComponent.

Unfortunately, when I entered the function I spelled it encodeUriComponent using camel case, which is what I thought was appropriate in this situation. Evidently not. I even was referencing good ol’ w3schools on the subject too.

But once again it kind of gets back to the whole “was it getElementByID or getElementById?” dilemma. And, unfortunately, unlike Visual Studio, there wasn’t IntelliSense in this case.

So then I set out looking to see why it was bombing, thinking that it was maybe a problem in Mobile Safari, like it didn’t support the function. I switched to escape and that worked just fine.

Then I looked more closely at the w3schools page and noticed the difference.

DUH.

Felt real stupid too.

But when using the function with the correct spelling/capitalization it worked just fine. Whew!!!

I guess I should have just copy-n-pasted.

;)

The Remote is Dead! Long Live the Remote!

Imagine my dismay when I discovered that my Apple Remote had taken a ride through the clothes washer and dryer a couple of weeks ago… As you may imagine, this journey rendered the remote inoperative and useless (albeit totally dry).

Apple Remote

Apple Remote

Additionally, searching on the Apple Store was a bit more depressing since the device is evidently no longer available… yikes.

eBay to the Rescue

Thankfully there’s eBay.

After nosing around a bit I was able to find several vendors who had very reasonable prices on basically brand-new remotes. I think mine ended up being $6.99 USD.

At any rate, it arrived today and I was very pleased to try it out while listening to iTunes and it works perfectly. At that rate I probably should have purchased a few extras just in case this happens again…

Let’s hope not.

Strange Behavior

My next task was to resolve a very strange and annoying problem if you have more than one Mac in the proximity while using the remote. This happened to me while on vacation — the remote was pointed at my MacBook Pro, but in addition to controlling it, my wife’s MacBook was also responding to the controller, starting and stopping iTunes while a movie was playing on my computer. Very interesting.

Thankfully it is possible to pair up your remote to your computer, and I’ve already paired the new remote with my laptop and will do the same with our other MacBook and its respective controller…

Whew!