Archive for 'Programming'

Sync-Async Pair Pattern

So no doubt you implement some kind of asynchronous operation pretty often in your code, and chances are like us you do it fairly haphazardly. Here’s a post about adding a little formality to that design:

Sync-Async Pair Pattern – Easy concurrency on iOS

Apple provides many tools for implementing concurrency in your application. NSOperationQueue, GCD, or simply using performSelectorInBackground:withObject: that is available on each and every object, are just some examples. The tools are there, yet implementing good concurrency is hard.

The solution I have found is not yet another tool, or framework, but a simple pattern. I have not found an existing name for the pattern so I call it Sync-Async Pair. The idea is to hide the complexity of asynchronous calls and call-back behind a facade, and have a straightforward synchronous implementation. An implementation that is easy to write, test and extend…

Definitely worth a read!

Continue Reading →

3D Pipeline

Here’s a good post to read for those of us who have no idea how you go about making a 3D game:

Making Drive Forever, Part 2: Fun with Pipelines

Ok. So, we know what we want our game to look like. And we want it to be 3D. So…er…how do we actually make a 3D game for iPhone?

Obviously there’s quite a few bits to this, but today we’re gonna look at making a 3D mesh and getting it to show up on your device…

… This is the cool bit. Now, there’s another program running on the iPhone, called MeshViewer. The phone needs to be on the same wireless network, and use something like Network Ping Lite to find out the IP address. Meshbuilder then sends the mesh to the phone over wifi, and it just pops up on the screen, which feels pretty frickin’ 2011…

Nifty! Also check out the announcement and Part 1 of the series, looks like this is going to be an interesting one to track.

h/t: @mrfungfung!

Continue Reading →

JavaScript Impact

Yeah, yeah, another post about Titanium or PhoneGap or something, you’re thinking? Well, not exactly:

iOS and JavaScript – for Real this Time!

Less talk, more action – Apple just approved two of my JavaScript games for the AppStore: Biolab Disaster and Drop. Both are free; go check them out. You can also play them in your browser here and here.

Both games are pretty simple (the source for Drop is only 300 odd lines long) and written with my JavaScript Game Engine Impact

So what’s so special about these two games now? They don’t use PhoneGap or Titanium. They don’t even use a UIWebView. Instead, they bypass the iPhone’s browser altogether and use Apple’s JavaScript interpreter (JavaScriptCore) directly…

… you might remember a post from October 2010 where I attempted the exact same thing. Back then I used the JavaScriptCore library that is already available on iOS and used by Apple in Mobile Safari. The problem was, that this library is “private”, meaning that Apple does not want you to use it. And since you can’t publish anything in the AppStore that uses private libraries I abandoned the idea.

However I recently revisited the project, because there was still a chance to make this work: JavaScriptCore is a part of the open source WebKit project. Instead of using the private library that comes with iOS, you theoretically could compile your own version of this library and bundle it together with your App. Which is exactly what I did…

Well, that’s certainly an intriguing approach yes. We recall a session we were at one WWDC a few years back — 2007, maybe? — which talked about doing exactly this on desktop OS X, where JavaScriptCore is public, but that seems to have pretty much fallen off the radar since. But speaking of Radar, if you like the idea of being able to use JavaScriptCore directly instead of the various cross-platform frameworks out there, as Gus Mueller suggests here:

Even better would be if Apple would make JavaScriptCore public, and even turn on the Nitro JIT for everyone. I suppose I should file a bug on that.

Remember, even though to all appearances yes it looks like your bug filing time is utterly wasted, they seriously do use it to help setting priorities inside Apple. So make your vote heard!

h/t: readwritehack!

Continue Reading →

Secure Credentials

If you store any kind of password in your app, you should stop doing that and read this article:

Storing and testing credentials: Cocoa Touch Edition

There’s been quite the media circus regarding the possibility that Sony was storing authentication credentials for its PlayStation Network credentials in plain text. I was even quoted in a UK national daily paper regarding the subject. But none of this helps you: how should you deal with user passwords? …

… The important point is that you never need to see that password—you need to know that the same password was presented in order to know (or at least have a good idea) that the same user is at the touchscreen, but that’s not the same as seeing the password itself.

That means that we don’t even need to use encryption where we can protect the password and recover it when we must check the password. Instead we can use a cryptographic one-way hash function to store data derived from the password: we can never get the password back, but we can always generate the same hash value when we see the same password.

Shut up Graham. Show me the code.

Here it is. This code is provided under the terms of the WTFPL

Much easier to implement now than try to explain why you didn’t later, indeed.

We rather like the license, too. Next time we get around to open sourcing something of our own, most assuredly we will use the WTFPL to do so!

Continue Reading →

Background Movie Audio

Well, this is kinda well timed; just a couple weeks ago we had a request to loop audio from a movie in the background in an iOS product. And we told them “nope, can’t do that.” Turns out Matt Gallagher promptly puts an article up on, well, doing that:

Background audio through an iOS movie player

Background audio in iOS is supposed to be as simple as entering a setting in your Info.plist and making sure your kAudioSessionProperty_AudioCategory is appropriate. This is true unless your audio is part of a movie file or is played in a movie player that has just played video — suddenly it becomes fiddly, hard to test, unreliable and changeable from version to version of iOS … Specific points will include:

  • why an application that also plays video has so much more difficulty with background audio than other kinds of applications
  • why background audio has broken multiple times in StreamToMe since iOS 4 was released, despite using no undocumented functionality and despite the documented API remaining nominally unchanged
  • why background audio is affected by seemingly unrelated choices like Apple’s HTTP live streaming and 3G network

I’ll also briefly look at quality management on a complicated program and how the largely undocumented behaviors of Apple’s video APIs make perfect testing impossible…

So, actually, for practical purposes “nope, can’t do that” is what you should tell a client who requests this, unless you are a complete masochist you loves putting in endless testing hours you’ll probably find it extremely difficult to get paid for. But hey, if you really want to, this is about the best advice you’ll find!

Continue Reading →


So if you’ve been reading us for a while you may recall our gushing endorsement of CrashReportSender, and why yes it’s been working quite nicely for us, handy piece of kit indeed it is; but we see that it has apparently been superseded:

Introducing QuincyKit: a rewrite of CrashReporterDemo, live crash management for iOS and Mac – AppStore ready!

Well then. Still uses PLCrashReporter, the user UI looks about the same … hmmm, actually, there doesn’t really seem to be too much novel in the code besides a bunch of references to that HockeyKit thing, apparently they integrate now.

Still, in case you missed said gushing endorsement above, we’re quite sure that it applies just as much to this reincarnation, so go check it out on github!

Continue Reading →

AirPrint Emulation

So we’ve got a feature request to implement AirPrint here, but we’re not terribly interested in bothering to pick up any of the HP printers listed there as supporting it as we’ve already got a couple printers from Brother here that serve all our printing needs quite admirably. However, it seems that there’s this “Printopia” Mac app that ought to take care of emulating AirPrint availability nicely:


Any of you used Printopia, Dear Readers? Is it in fact an adequate substitute for testing your AirPrint functionality with a genuine device? Or do you have any other advice for how to adequately test AirPrint without acquiring yet another box to clutter up the place?

And as an aside, if like us you’re interested in picking up Printopia now, we note that — conveniently — there’s one of those bundle deal thingys going on right now where for another $30 of those increasingly cheaper by the day USian dollarettes over the $20 Printopia costs, you get a fairly impressive-looking collection of useful stuff to go along with it like Screenflow and Amadeus Pro and Contactizer Pro that look quite potentially useful for the harried developer. So you might want to check that out!


Thanks to Goran Blažič for pointing out AirPrint Activator — our printers Scribble and Holstein (she’s the black and white one, geddit?) are indeed sharable so that would probably work as well, but Printopia seems featureriffic enough that we figure we’ll go with that option.

Continue Reading →

Tip: Low Memory Warnings

Hey, here’s a handy tip for scheduling low memory warnings for your debugging pleasure: use AppleScript!


I wanted to share a tool that I use in as part of checking an app for behaving correctly under low memory warnings, to the extent that is possible to do so using the Simulator. It’s an Applescript that just sends a low memory warning to the simulator every second or so, so you can go through every function of your app while debugging and see if a low memory warning ever causes a crash…

It’s simply triggering the ‘Simulate Memory Warning’ menu item repeatedly for you … but hey, there’s been times that we wanted to simulate low memory conditions whilst in the midst of an action that required our full attention, and it never occurred to us to whip up a script like this…

h/t: @politepix!


Note in the comments that there’s an unofficial API call “_performMemoryWarning” you can use for the same purpose in code:

[NSTimer scheduledTimerWithTimeInterval:1.0 target:[UIApplication sharedApplication] selector:@selector(_performMemoryWarning) userInfo:nil repeats:YES];

That will work nicely on the device no doubt. Just don’t forget to remove it before submitting!


Here’s a programmatic way to do this in the Simulator:

Debugging Magic: Auto Simulate iOS Memory Warnings

Continue Reading →


So one of these days we’ll get around to taking a look at this “Tweetbot” thingy that’s got everyone all excited, but in the meantime, apparently there is at least one nicely done bit of UI that you can get your own implementation of here:

iOS Code: TweetBot like AlertPanels

TweetBot is sexy, no one can deny it. One of the coolest aspect of TweetBot is the unobtrusive panels that show what is happening on the app … Apple uses a HUD for “disconnected” errors/alerts but unfortunately, most apps have been using them for showing a modal progress or other miscellaneous information. A cleaner way would be to use a sliding alert panel like TweetBot. To make life easier for developers, I have made a class, MKInfoPanel, which does exactly that…

Nothing too tricky about it, but hey there it is on github for you, and yes those little popdown panels are kinda nifty. We’ll definitely consider using those instead of UIAlertView for information displays in the future!

Continue Reading →


Here’s a commercial library that’ll save you some time if you need it:

Superpin is a drop-in replacement for MKMapView that automatically clusters annotation views.

  • Blazingly fast: handles up to 50.000 annotations at once in milliseconds
  • Easy to use: Drop a single .framework into your project, change MKMapView to SPMapView and you’re good to go!
  • Comes with source-code and extensive documentation

Yep, that could be handy. The demo project of all the world’s airports shows it off nicely:

Screen shot 2011-04-25 at 12.13.48 AM.png

It’s $299 for the source code, and $99 for a binary only version. Although note from this tweet:

Use COCOANETICS for 30% off

So there you go then, cheaper than writing it yourself no doubt!

Continue Reading →
Page 30 of 93 «...10202829303132...»