Joris Kluivers

I like to build software.

Future Proofing: Calling New APIs on Old Devices

When building applications you’ll eventually have to deal with different versions of the OS or availability of features. Adoption of a new iOS version is usually pretty fast, but uptake for a new version is still measured in months. And even after an OS upgrade, some features might never be available because of hardware limitations.

The easy solution is to just limit your app to certain hardware or OS versions. Better of course is to support new features when available and fallback or leave those features out on older OS versions and older hardware.

Read more below about methods to deal with new API’s on older devices.

Weak References to NSProxy With ARC

The common pattern to declare delegates when using ARC is using a weak ownership:

1
2
3
@interface MyObject
@property(nonatomic, weak) id<MyObjectDelegate> delegate;
@end

However using a weak delegate this way recently failed without apparent reason:

1
2
3
4
myObject.delegate = aDelegate;
// delegate property is still nil
NSLog(@"myObject.delegate: %@", myObject.delegate);
// Logged: 'myObject.delegate: (null)'

I was testing my class using OCMock and used +[OCMockObject mockForProtocol:] to create my delegate. Turns out OCMock is creating mocked objects as NSProxy subclasses, and ARC has issues with weak references to proxies.

New Objective-C Literal Syntax for NSArray, NSDictionary

Apple committed a new patch to the llvm project adding support for new Objective-C literalsyntax for NSArray, NSDictionary and NSNumber. These have previously been documented in the Mountain Lion Xcode release notes but that was still under NDA. Now that these features have been committed to llvm I guess we’re allowed to speak about it.

Kiosk Mode for iOS

You’ve probably been in an Apple store and seen this: every product is accompanied by an iPad that shows features, comparisons and allows you to ask help from a store clerk. The app that makes this possible runs in a kind of kiosk mode: there’s no way to exit the app because the home button is disabled.

This mode is actually not a feature of the app but a system wide thing controlled by the OS. It’s possible to configure every device to lock into any app using this so called Store Demo mode. All it takes is a single configuration file.

Custom Popups Revisited

One of the most popular pages here is an old (iOS 2.x era) post that describes how to subclass an UIAlertView to customize it’s appearance. That post describes how to transform the default blue popup into something more arbitrary.

However ever since that post I’ve come to the conclusion you don’t want to subclass UIKit classes, unless they were specifically designed to do so. A UIAlertView was definitely not designed to subclass. Time for a post on how to do this correctly.

Consolidating My Web Presence

In an effort to consolidate my web presence I relaunched joris.kluivers.nl. From now on there will be only one place to find me online, and you’re currently looking at it.

Up till now there have been several places where I wrote content. An abandoned blog at blogger.com, a custom wordpress blog with one or two posts a month and a few random pages where I published software. From now all this content (dating back to 2005) will be available here at this domain.

Best Improvement in Twitter 4.1 for iOS

The Februari 21 release post for the new Twitter version doesn’t mention my favorite improvement. Ever since the new UI was launched I had the feeling the app didn’t work very well together with app switching. Every single time I opened the app I was presented with a splash screen with a big logo, not a good sign in the age of iOS multitasking. The app was starting up fresh each time because the OS had shut it down, or worse: they presented this logo on purpose delaying me from seeing my timeline.

The 4.1 version solves this.

My New Favourite: Easy Async NSURLConnection

Single line URL connections! I actually made my own category on NSURLConnection before, to do a similar thing. I’m happy this is now obsolete and I can use the iOS5/OSX10.7 built-in.

1
-[NSURLConnection sendAsynchronousRequest:queue:completionHandler];

Example:

1
2
3
4
5
6
[NSURLConnection
    sendAsynchronousRequest:request
    queue:self.queue
    completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    // do something useful
}];