Archive for November, 2010

30
Nov

UINavigationController Cube Transition

Here’s some code for a not bad looking little scrunchy push-ish transition for the case of jumping out of one hierarchy and directly to another off the root with a UINavigationController:

UINavigationController-CubeTransition

There’s a video showing it here as well.

At this exact moment what we want to do is not jump around in a navigation hierarchy but toggle between a navigation stack and a plain UIView, but the code looks pretty applicable to that as well. If we run into any problems with that, we’ll be sure to let you know!

h/t: @fabiankr!

POSTSCRIPT:

Yep, took us 9 minutes flat to convert the code linked above into a UIWindow method to replace its main view with a transition and test, works perfectly and looks quite appropriate for the use case we’ve got for the switching between error view and navigation stack here. Ex-cellent!

29
Nov

Tip: Ordered JSON

Question of the day:

How to create a JSON from an NSDictionary keeping the order of the elements you added?

You know, we actually ran into an issue with that kind of thing a few months back. But we did not find a solution this elegant:

Use an OrderedDictionary!

“A what?” you say? Why, that’s from this Cocoa With Love post from a couple years back:

OrderedDictionary: Subclassing a Cocoa class cluster

The default Cocoa collection classes are highly capable but there are situations where you may need to override them to alter their functionality. I’ll explain when and how you should do this with an example class: OrderedDictionary (an NSMutableDictionary subclass that maintains ordering of its keys)…

Interesting tips there even if you don’t actually have any immediate use for an ordered dictionary!

28
Nov

Tip: Resource touching

So you got a project with multiple hundreds of resource files changing in each build in a Folder Reference in Xcode, and you’re getting annoyed that it’s not updating them on the device automatically, like it should? Well, here’s a workaround for you:

Xcode resource groups and folder references when building for iPhone

Boils down to

  1. Add a ‘Run Script’ build phase.
  2. Change the shell to /bin/tcsh.
  3. Put in the script:   touch -cm ${SRCROOT}/the/folder/path
  4. Drag to after the ‘Copy Bundle Resources’ phase.

And there you go, aggravation greatly reduced, indeed. Hopefully Xcode 4 will be more clever about this kind of thing…

27
Nov

ValidateStoreReceipt

You putting together a Mac App Store project? That Validating App Store Receipts bit looking annoying to implement? Well, just pop on over to github and grab

ValidateStoreReceipt

At the end of October 2010 Apple announced the App Store for Mac. The App Store will put a receipt into your app bundle, but won’t implement any copy protection scheme.

Unfortunately this document doesn’t tell you how to process this receipt in detail, quote:

The payload of the PKCS7 container is encoded using ASN.1, as described by ITU-T X.690.

This validator parses and validates the payload and the PKCS7 container itself.

Why, how convenient, indeed. If it doesn’t work as advertised, we’ll be sure to let you know shortly!

26
Nov

When To Start Marketing

So let’s take a little break from coding today and read an excellent article about when to start marketing the products of that coding; and exactly when is set out straightforwardly in the title,

Why You Should Start Marketing the Day You Start Coding

Indeed. Time and again … and again … and again … we’ve finished up massive projects that everyone agrees were executed with magnificent skill and aplomb, and they go on to pretty much disappear without a trace because nobody involved has clue one about marketing. And there’s a pretty strong correlation between that and people who want to keep the development secret. As the article says,

Let me address the fear of someone stealing your idea with the following: Wake the hell up! No one cares about your idea…

And if someone does steal it before you launch, consider it a favor.

Having your idea stolen sooner saves you the hassle of building it, only to have someone steal it then. If it’s that easy to steal it’s going to happen one way or the other…

Why yes, yes that is true. Next time somebody insists on an NDA before they describe their project, we’ll just point them at this article. Actually, given how much of a waste of time those people generally turn out to be, we’ll probably tell them to wire us $2500 along with the NDA text to pay for our lawyer to review it. That should weed out the unserious ones right nicely.

As far as practical advice goes, the only real takeaway is that you should put a landing page up soon as you decide to move forward. Most importantly, for concept validation:

In 2-4 hours you can setup a landing page and begin collecting emails. This simple act (coupled with a small amount of marketing) can make the difference between having the confidence that you’re building something people want, and having no clue if you’re pouring several person-months of effort down the drain…

Imagine yourself three months into building your product. You have three months left. You’re tired because you work every night until 1am. Your wife tolerates it, but she’s not happy about all the time you spend sitting in front of your computer with no money to show for it. And you haven’t seen your friends in months…

… assume you have 650 targeted email addresses you’ve compiled through some small marketing efforts and a landing page. Suddenly things don’t look so bleak. You have some sales waiting for you once you push the bits to your server.

And vice versa, if you’re three months in and you’ve received several thousand uniques to your landing page but only 6 sign-ups, you have a problem. Either your landing page stinks or your idea is a lead balloon.

Either way, you need to put coding on hold and figure out the problem.

Yep, yep, yep, yeppers. We’ve also noticed a very striking correlation of success with clients who believe in the release early release often mantra, and an equally striking correlation of failure with clients who believe in perfecting their vision, as opposed to incorporating any customer feedback, down to the virtually unnoticeable detail before they spring it upon the world, as Athena from the brow of Zeus … except to pretty much complete indifference.

Not that perfectionism is bad in and of itself mind you, you can make a decent argument it’s necessary for sustainable success in fact, but you can’t allow it to impact release schedule so you have to trade features off for it, even features that most people would deem necessary if you asked them. Exhibit A: How long was it before the iPhone had copy and paste again? How much sneering was there among the technorati over that? How much difference did that make to the iPhone’s success? Yep, that’s about right. We could call that the Copy & Paste Principle perhaps, and apply it to every feature request that would involve a release date slip.

But in the meantime, we recommend you read the whole article. Hopefully nothing in it you find shocking, or even particularly surprising, but it does lay out its prescriptions quite clearly and compellingly.

25
Nov

Heart Rate Monitoring

Now this is a seriously nifty idea: Turn on your iPhone’s flash, hold it up to your finger, and mess around with frames from an AVCaptureSession to figure out your heart rate based on the color changes.

Heart Rate Free – How it works

I’ve had a few emails asking for information on how my app Heart Rate – Free works.

There’s nothing particularly clever about it, it just uses the camera to pick up the slight change in the colour of the light coming from the flash as the blood flows in and out of the finger.

You can make a few modifications to the code posted in the Augmented Reality Post or download the demo code

Personally, we’d say that coming up with a novel application like this is pretty much the very definition of clever!

h/t: iPhoneSDK!

24
Nov

Core Animation samples

Here is a project building a most excellent collection of all kinds of visualized examples of working with Core Animation:

CA360 – Core Animation Examples for iOS

The code in this project was originally created for a presentation at the fall 2009 360idev conference in Denver, CO. I have continued to add to it and update the examples, and it is now the repository for all of my Core Animation examples and sample code, whether they are for blog posts, articles or conference presentations.

Just about guarantee you’ll find something helpful in there even if you think you know Core Animation pretty well!

h/t: @Cocoanetics!

23
Nov

In-App App Store

Here’s a nicely packaged up controller for doing cross-app promotion with an HTML view:

In-App App Store, also intro to git submodules

… As soon as you have multiple apps in the store you should make it easy for users to purchase any app from within any other app. The idea to create your own little app store that you will embed in every one of your apps. This is what we are calling an “In-App App Store”, which we will abbreviate to IAAS from now on.

You place a button somewhere on your root view that gives a hint of a call to action, such as a little wiggle or pulsating animation. When the user taps this button one of two things happens: if the user is on an iPhone, display a full screen, 320×480 modal view, and if the user is on an iPad show a 320×480 popover pointing at the button. Inside this view you put whatever you want to help cross sell your other apps. I chose to write a very short blurb about Opetopic and then display the icons to my other apps. Here is what it looks like in IsoCards and my new game, Battle Nation:

BattleNation-OAS-example-175x300.png

Nothing too tricky or unusual, but hey working code is always handy yes? Available on github for your cross-promotional enjoyment.

UPDATES:

Apparently inspiration strikes twice, or something — just a couple days later, here’s another take on the same subject:

Promoting Your Other Apps Within Your Apps

And yet another, on the wonderfulness of simple one line text messages:

The Perfect Newsline

22
Nov

MobileSafari on 4.2

So there was a new iOS version out today, no doubt you noticed; but did you notice all the nifty new stuff in Safari? Nope, us neither, and it’s not documented yet apparently … but some people are hardcore enough to dig around themselves:

Safari on iPhone & iPad 4.2: Accelerometer, WebSockets & better HTML5 support

Apple didn’t update yet Safari documentation to reflect these new APIs. This information is based on JavaScript research and testing over Safari itself I’ve been doing. The list of new features I’ve detected are:

  • Accelerometer support through the DeviceOrientation API
  • WebSockets API from HTML5
  • Updated HTML5 Form Support
  • Partial XHR-2 Support
  • Print Support
  • New JavaScript data types
  • New DOM events
  • Enhanced SVG and Canvas support

All that’s pretty neat yep, and from the comments here’s another one:

@font-face has worked for a long time on iOS given some specific caveats. However, the new news on web fonts in 4.2 is that iOS now prefers the TTF version of a font over the SVG version (formerly SVG was the only format supported.)

The other nice thing about web fonts on 4.2 is that they now work in offline webapps. This was a big deal for me and I only discovered it by luck. Still; this will be a pretty handy feature for a lot of folks I think.

Presumably all these new goodies will apply to your embedded UIWebViews as well.

POSTSCRIPT:

The site PADILICIOUS, mentioned in this year’s WWDC videos, has a wide range of iPad/MobileSafari focused good stuff!

21
Nov

RAGE Tech Tidbits

So you pretty much can’t possibly have missed that id brought out this game RAGE recently, no doubt — but you might have overlooked this interview over at bethblog.com, and if so you should read it:

John Carmack discusses RAGE on iPhone/iPad/iPod touch

There’s a bunch of obscure tidbits of information on optimization and OS limitations therein that you probably won’t see anywhere else. Most of which are probably not going to impact your daily work unless you are, in fact, John Carmack; but interesting nevertheless, like these notes on file access,

… Interestingly, you can only memory map about 700 megs of virtual address space, which is a bit surprising for a 32 bit OS. I expected at least twice that, if not close to 3 gigs. We sometimes have a decent fraction of this mapped.

A page fault to a memory mapped file takes between 1.8 ms on an iPhone 4 and 2.2 ms on an iPod 2, and brings in 32k of data. There appears to be an optimization where if you fault at the very beginning of a file, it brings in 128k instead of 32k, which has implications for file headers.

I am pleased to report that fcntl( fd, F_NOCACHE ) works exactly as desired on iOS – I always worry about behavior of historic unix flags on Apple OSs. Using this and page aligned target memory will bypass the file cache and give very repeatable performance ranging from the page fault bandwidth with 32k reads up to 30 mb/s for one meg reads (22 mb/s for the old iPod). This is fractionally faster than straight reads due to the zero copy, but the important point is that it won’t evict any other buffer data that may have better temporal locality…

Or these on sound,

… OpenAL appears to have a limit of 1024 sound buffers, which we bumped into. We could dynamically create and destroy the static buffer mappings without too much trouble, but that is a reasonable number for us to stay under.

Another behavior of OpenAL that surprised me was finding (by looking at the disassembly) that it touches every 4k of the buffer on a Play() command. This makes some sense, forcing it to page the entire thing into ram so you don’t get broken sound mixing, but it does unpredictably stall the thread issuing the call. I had sort of hoped that they were just eating the page faults in the mixing thread with a decent sized mix ahead buffer, but I presume that they found pathological cases of a dozen sound buffers faulting while the GPU is sucking up all the bus bandwidth or some such. I may yet queue all OpenAL commands to a separate thread, so if it has to page stuff in, the audio will just be slightly delayed instead of hitching the framerate…

And naturally it finishes up with that inimitably Carmackish pontification for your chuckles:

… I had been harboring some suspicions that our big codebases might benefit from the application of some more of the various “modern” C++ design patterns, despite seeing other large game codebases suffer under them. I have since recanted that suspicion.

Not that we’re in any way backtracking on our solid belief that maintainability is the only coding metric worth optimizing until alternative necessity is completely overwhelming, for mere mortals; but hey, if you’re producing at a John Carmack level, you’re entitled to whatever code design philosophy you darn well please!