Tuesday, December 15th, 2009

PastryKit: An iPhone Webdev Library from … Apple

Category: iPhone, Library, Mobile

<p>

John Gruber has spotted a library for iPhone web apps, from none other than Apple. This mysterious library, called PastryKit, seems to have flown under the radar as a Google search reveals precious little on it. In similar vein to other efforts, Apple’s library provides support for native-feel websites – websites that run in Mobile Safari, but feel like native apps. (That’s the objective anyway; some look-and-feel emulators are “good enough”, while others get stuck in the uncanny valley).

To get hands-on with PastryKit:

  • Visit http://help.apple.com/iphone/3/mobile/ from your iPhone or iPod Touch. This is an official Apple site using PastryKit. If you’re feeling lazy/iPhone-challenged, watch Gruber’s screencasts.
  • Now with the same site in regular Safari (on your Mac/PC), open up the Develop Menu (if it’s not there, enable it in Preference|Advanced). Choose User Agent > Mobile Safari 3.0 (or probably any other version number). And now you can see it in your browser. From Develop Menu, Web Inspector will let you view the script.

The HTML includes PastryKit as follows:

  1. <!-- PastryKit -->
  2.     <link rel="stylesheet" href="dist/PastryKit-ug-compact.css">
  3.     <script type="text/javascript" src="dist/PastryKit-ug-compact.js" charset="utf-8"></script>

PastryKit Javascript and PastryKit CSS are available. Unfortunately, they’re a bit unclear due to compression, but Gruber nonetheless pored into the source:

PastryKit accomplishes all three of the aforementioned things — hiding the MobileSafari address bar, providing fixed-position toolbars, and providing scrolling with momentum — by disabling regular scrolling and setting up its own view hierarchy and implementing its own scrolling.

The whole question of native iPhone apps was a hot topic last month after PPK whipped up a storm on the question of web apps replacing iPhone apps. The really interesting thing here is Apple’s stance. They launched the iPhone with web intended to be the platform for 3rd party apps, then switched over to native apps and haven’t done much to facilitate native-style web apps since then. Is a change coming? As Gruber puts it:

The $64,000 question, though, is whether PastryKit is something Apple intends (or that a team within Apple hopes) to ship publicly. It seems like a lot of effort to build a framework this rich just for this iPhone User Guide, so I’m hopeful the answer is yes. Perhaps something integrated with the next major release of Dashcode? And, perhaps with integrated UI layout tools, along the lines of Interface Builder?

As well as apperaring in the user guide website, Chris Messina noted PastryKit apparently appears in the iTunes LP files.

Related Content:

Posted by Michael Mahemoff at 8:31 pm
8 Comments

++++-
4.3 rating from 30 votes

8 Comments »

Comments feed TrackBack URI

Apple’s purchase of lala.com makes sense when you combine it with this library. Apple is going to launch a web-based version of itunes, and obviously this needs to work well on the iPhone. So, at the very least they’re going to use this in-house to build iTunes for web. Given that they usually release their in-house development tools, I would put reasonable odds on this shipping to a wider audience.

Comment by Joeri — December 16, 2009

I wonder why Apple decided to create a JavaScript library for things like scrolling and fixed position elements instead of adding support to the browser itself. Seems a bit odd.

Comment by devongovett — December 16, 2009

@devongovett:
PastryKit may have been written by another team separate from the Safari team, hence why fixed positioning wasn’t native. PastryKit has only really been used by iPhone’s tutorial/help app.

Comment by Jordan1 — December 16, 2009

The good thing about the code is that it’s not obfuscated. Here is a “reformatted” version of the code:

http://albeik.com/pastrykit/PastryKit-ug.js
http://albeik.com/pastrykit/PastryKit-ug.css

Still reading through the code for analysis…

Comment by albeik — December 16, 2009

unfortunately it sounds as if the framework is not officially released, but rather is a “stealth framework” developed internally, and would probably be inadvisable to use directly due to licensing issues (or lack thereof, which may be more dangerous).

any word on when/if this will be made available publicly on developer.apple.com? seems like it sure would be useful…

in the meantime, it’s definitely worthwhile perusing the js & css to get some ideas/insights.

Comment by InteractiveLogic — December 16, 2009

there is good discussion about this in this hacker news thread: http://news.ycombinator.com/item?id=997508 also, in that thread you can see that I (and a bunch of other people) have pulled down the code, unobfuscated it and put it back up on github. go check it out.

Comment by ryshaw — December 16, 2009

Great resource. Its about time they made something like this sheesh! Thanks.

Comment by iphonedevelopment — December 16, 2009

check this out
http://cubiq.org/scrolling-div-on-iphone-ipod-touch/
demo http://cubiq.org/dropbox/abc/

Comment by lisadmc — June 4, 2010

Leave a comment

You must be logged in to post a comment.