-
URL Encoding an NSString on iOS
I’ve been working on an iPhone app for the last few weeks, which I’ve really enjoyed. Every now and again, though, you hit what seems like a bug in the iOS SDK. This seems to happen much more frequently than it ever did when I was coding in C#. As a result, my default debugging approach – that any problem with my app must be my fault rather than something in the framework – has shifted slightly. I’m now much more likely to question the framework itself, and with a quick Google search it’s common to find other developers who have experienced the same problem.
Here’s one that bit me recently.
NSStringhas a method calledstringByAddingPercentEscapesUsingEncoding, which purports to make the string safe for use, say, as a parameter to a URL. There are several characters that are reserved in parameters to URLs – for example the slash character, or the ampersand, because these are characters that are used to delimit the URL itself. Therefore we encode these, and this is done using the percent encoding scheme.As an example, if you want to use the string hell & brimstone + earthly/delight (and why wouldn’t you?) as a parameter to a URL then you’ll need to convert it to hell+%26+brimstone+%2B+earthly%2Fdelight so that the ampersand becomes
%26, the plus becomes%2Band the slash becomes%2F. Note that spaces are encoded as pluses, which is why the original plus sign needs to be encoded.But
stringByAddingPercentEscapesUsingEncodingdoesn’t respect these rules, and actually produces this: hell%20&%20brimstone%20+%20earthly/delightIt fails to encode the ampersand, the slash and the plus, and many (most?) web servers will be confused by that. It encodes the spaces as
%20, which is just as acceptable as encoding them as a plus.In short, it’s completely broken, which is frustrating. But thankfully there’s a lower-level API we can use which, thanks to the magic of Objective-C categories, we can tack on to NSString. This is based on a blogpost by Simon Woodside, which I’ve just turned into a category.
Here’s the category’s header file:
#import <Foundation/Foundation.h> @interface NSString (URLEncoding) -(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding; @end
And here’s the implementation:
#import "NSString+URLEncoding.h" @implementation NSString (URLEncoding) -(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding { return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding)); } @endAnd now we can simply do this:
NSString *raw = @"hell & brimstone + earthly/delight"; NSString *url = [NSString stringWithFormat:@"http://example.com/example?param=%@", [raw urlEncodeUsingEncoding:NSUTF8Encoding]]; NSLog(url);
And the result will be exactly as we hoped:
http://example.com/example?param=hell%20%26%20brimstone%20%2B%20earthly%2Fdelight -
Antennagate: Can Schopenhauer Help?
Ever since the media eruption over the iPhone 4’s antenna design, I’ve been thinking about how we assign meanings and experience real emotions in response to representations, or illusions.

Adapted from a photo by Jamais CascioTake the bars on your mobile phone. We are completely used to telling the person on the other end of the line that we “don’t have many bars”. Yet “bars” are just a way that mobile phones have of indicating how good a signal they have, not an actual measure of anything real. But by now we’re so used to them that we use them as though they were the actual thing rather than a representation of it, and we can have furious arguments about “dropping bars”.
Think about the way that Steve Jobs presented the way that the iPhone 4 and other smartphones suffer from signal attenuation when gripped in specific ways. He compared the upper limit of the number of bars displayed when gripped as recommended by the manufacturer against the lower limit of bars displayed when held “wrong”. Never did he mention the actual signal degradation in dBm, only ever the way that the phone manufacturer had chosen to represent them in terms of bars displayed. In one telling moment, he pointed out that the Android phone only used four bars, and yet he didn’t take the next logical step and conclude that we can say nothing meaningful about actual signal loss by looking at an abstract representation.
There was a storm of protest (from me too, I confess) when Apple published a “letter” explaining that the algorithm they used to calculate the number of bars to display was flawed and exaggerated the level of signal. We complained that this was simply deckchair rearrangement: the problem was a loss of signal, we insisted. What were Apple going to do about that? And yet the only evidence we had for the “loss of signal” was the representation – the bars themselves! That reaction occurred because we couldn’t handle the idea that the representation had been unhelpful because we do not see it as representation.
-
Made by Many Talk: John-Henry Barac on the Guardian iPhone App
We’ve held some interesting talks here at Made by Many over the last couple of years, and I’m thrilled to announce that we’ve got an exciting one coming up next week.
We’ve invited John-Henry Barac, the designer of the tremendously successful Guardian iPhone app, to come and share his experiences in designing a newspaper app for the iPhone. Our friends at BBH London have kindly agreed to provide a room for the talk, for which we’re very grateful.
The Guardian iPhone app has been a huge hit, and recently won the innovation award at the AOP awards, where the judges said that it “broke the mould of how content to mobile can be monetised”.
The Guardian have long had a reputation for small innovative projects that help to point the way towards a future for quality online journalism, and the iPhone app is an excellent example of that approach. While other newspapers circle the wagons, the Guardian is committed to quality journalism that plays a full part in what Steve Jobs calls ‘the open web’, but have still scored a hit with a paid-for application.
What specific issues were there in developing the Guardian app? Can print publications simply transition to tablets and phones by preserving the page metaphor, or do they need to re-imagine what they do at a more fundamental level? Should they follow Apple’s lead and adopt skeuomorphic interfaces, or should they turn their back on the paper-based past entirely? How can newspapers and magazines develop new services on this new class of mobile device?
These are just a few of the issues that John-Henry will offer an opinion on, and he’s ideally placed to do so. He spent a decade at the Guardian on the print side as an art director, and is therefore both an insider and an outsider; a print man helping to forge a digital future. His is a fascinating perspective on this most hotly debated areas of digital culture.
The talk will start at 1pm on July 15th at BBH London’s offices at 60, Kingly Street, London, W1B 5DS and will last for between 45 minutes and an hour, depending on the number of questions.
We’d love you to come to hear what John-Henry has to say, and to put your own questions to him in person. If you’d like to attend the talk, please email me at james@madebymany.co.uk. There are – obviously – limited spaces available, so it’s best to book your place early.
-
Hacking Safari Reader For Even Less Distraction
If you’re on a Mac an you haven’t tried out Safari Reader yet, you should. It’s a really simple but incredibly useful little feature that detects when you’re on a page with a lot of text, and offers to display that text in a reduced distraction popup. (Update: thanks to reader Tom Harvey, who points out that Safari is also available on Windows, and you can use the same technique to hack the reader display there.)

Safari shows this little icon when Reader is available.This morning, I visited an an article page suggested to me by a colleague, but the annoying animated Flash ads underneath the overlay were still visible and distracting, because the Reader panel doesn’t take up the whole width of the browser window, and the overlay is somewhat transparent (20%, it turns out).
There’s actually an easy way to hack this so that the overlay is completely opaque. Safari Reader’s UI is provided by an HTML file embedded in the Safari application bundle, and that file contains all of the CSS used to control its appearance.
Here are the steps to make the background completely opaque and distraction free.
First, open the Finder, and locate Safari inside the Applications folder. Control-Click (or right click if you have it enabled) on the app file and select “Show Package Contents” from the popup menu. This will bring up a new Finder window, with a single Folder in it, called “Contents”. Inside the Contents folder, there’s a folder called Resources, and inside that is a file called “Reader.html”
Now, open Reader.html in your favourite text editor, so Control-Click and chose Open With… and select your editor from the list. If you don’t know which app to use, your best bet is probably Text Edit.
Inside Reader.html there are a bunch of CSS styles, but the one you’re looking for is #background, which is on line 122 of the file. By default, this sets the opacity to 80%, so changing the last number in the background-color directive from 0.8 to 1 will make it 100% opaque.
The only drawback to this approach is that when Apple updates Safari, you’ll need to reapply the hack because the update will overwrite the entire application bundle.
Here’s what that CSS code looks like once you’ve made the change:

Now, save the file. OS X may ask you to enter your admin password in order to save the file. Once the file is saved, restart Safari and enjoy your new completely distraction-free reading.
-
Wanted: An Exceptional Objective-C Developer
We have a very small and talented development team here at Made by Many. We’re technology agnostic, and while we have a very strong Ruby backbone, we regularly supplement our in-house skills with specialists from a range of disciplines. Most often we do this with a trusted network of specialists. But now we are ready to add an exceptional Objective-C developer to our team.
The primary focus for this new role will be – of course – the iPhone and iPad (not forgetting the iPod Touch).
Why would you want to join Made by Many? We’re not like other companies. We are relentlessly focused on user experience through a synthesis of great design and great technology. We have a great client list, and we’re adding to it so fast that we can’t keep the clients page on our website up to date.
We work in a highly collaborative and open way, and individuals can make a big impact here. We don’t have departments or organisation charts. We work in small project teams, using Agile methodologies, in close contact with our clients. Technologists are integral to what we do, and without exception are involved from the inception of every project and at every stage thereafter. We all have strong opinions yet we are all open-minded. There’s a wealth of experience in our team, yet a hunger for new ideas. We believe that technology is a powerful force for good, and we love experimenting with new stuff.
Almost everything about the role is up for discussion, and the specifics will largely be down to the right candidate emerging. Naturally, we will offer a competitive salary and a good range of benefits. Not just the normal ones, either, although we offer those too. For example, this year almost all of us went to SXSWi, with the company picking up the large majority of the tab.
Obviously, you will need to be a very talented developer with a deep knowledge of the iPhone SDK, and a proven track record in Objective-C development. We will also expect you to have a solid understanding of fundamental web technologies, and the fundamental tools of software engineering. Everyone at Made by Many talks to clients, and you’ll need to be comfortable with attending and contributing to client meetings. We’re not looking for code monkeys who shrink from human contact.
We’re really excited about this opportunity, and we can’t wait to hear from candidates. Please send a copy of your CV and a brief covering email to james@madebymany.co.uk along with any questions or comments. Absolutely no agents, please.
-
iPhone OS 4.0: Now With Added Evil
Hidden among the details of Apple’s announcement of the next version of the iPhone operating system last week was a nasty, snide little addition to the terms and conditions that iPhone app developers must agree to in order to get their apps into the App Store.
In effect, it says that you must use Apple’s developer tools and preferred programming language to develop iPhone apps. Which, on the face of it, is uncontroversial. It’s Apple’s platform, so you use Apple tools and languages. The problem is that there are significant efforts from other companies and projects to make it easier to transition to iPhone app development from other platforms, such as Microsoft’s .NET and Adobe’s Flash, as well as to make it easier to write apps that run on multiple mobile platforms. Apple’s devotees have had problems with these alternative platforms before, as I wrote a few months ago, but now Apple have taken the extraordinary step of embedding their own language preference in the terms and conditions of even being an iPhone developer at all.
The new rule expands section 3.3.1 of the developer agreement to state that “applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine”. Objective-C is the language that most developers use to write applications for Mac OS X, and it’s by far the most popular language for iPhone apps, too. C and
C++ are probably the most popular languages for writing games, a key part of the App Store’s success.Apple have had problems applying their guidelines consistently in the past, and that’s partly because the wording of the developer agreement is fairly loose. The new additions are no exception.
-
Umair Haque is Confused About the iPad
It’s been a tough month for Umair Haque. First, he conducted the world’s most boring and pointless interview at SXSWi, and now he blogs his extraordinarily muddled thoughts on the iPad.
It’s tough to sum up what he’s saying because it’s so confused. He seems to want the iPad to be more open both physically and in terms of installing apps and content. This is understandable in some ways, but he’s an economist, and his argument seems to be saying that Apple will not succeed with the approach they’ve chosen for fundamental market-based reasons. It’s just that he fails to provide any evidence at all that this is so.
Let’s take it one paragraph at a time.
The iPad’s like an amazing hairdresser — who wants to monitor your bathroom for authorized shampoo, conditioner, and water. By building a device that liberates services, but locks down “product,” Apple’s shooting itself in the iFace. It’s as if Apple wants to step into the hyperconnected network age — but also keep one foot firmly planted in the industrial era.
Hahahahaha! iParadox? iFace?! Those are great gags! Oh, hold on, I think I just pissed in my iPants.
Puerile jokes aside, the analogy is nonsense. Critics of the openness of the iPad (and the iPhone) often conveniently ignore the fact that it has unmoderated access to the entire internet (minus anything written in Flash) through its browser, Mobile Safari. The entire pitch for the iPad emphasises this: “it’s like holding the Internet in your hands”.
-
iPhone Abroad: Usability Nightmare
Last month almost the entire company decamped to Austin for the South by Southwest (SXSW) interactive festival. My experience with my iPhone there was frustrating, to say the least.
My carrier, O2, prices a 3G data connection when abroad so rapaciously (at £6 per megabyte), that there’s no realistic option of having a network connection when abroad, unless you can find a functioning wifi network. Open wifi networks appear to more common in Austin than they are in London, especially in hip cafés and bars (not that I ever visit such places in London), but at times when you are genuinely out and about, you’re stuck with no data at all, and the iPhone in effect becomes an iPod Touch.
To be fair to O2, something that does not come naturally to someone who’s been consistently underwhelmed by them for years such as myself, they do send you a text message as soon as you emerge from your airplane mode, warning you about what a rip off their data roaming charges are. At those rates I’d have more respect for them if they walked up to me with their finger making a pretend gun in their coat pocket and asking for my dinner money.
-
Can there ever be an online masterpiece?
One of the SXSW sessions I attended today was the Ze Frank session on the ‘creative lifestyle’. I found it a bit pointless, really. It appeared to be a love-in between Frank and a room full of his fans. But it did get me thinking about art and the internet.
The examples of Frank’s work left me unimpressed. I find them whimsical, disposable and inconsequential. I can see how they would provide some moments of entertainment, but this isn’t what I’m interested in. As I get older, I find myself more and more interested in identifying things that I can safely ignore and getting rid of them for good. My goal is to spend an extremely high percentage of my time on what I would like to call masterpieces.
I realise that this puts me in a minority, but it’s something I’d like to explore here for a little while. Please understand that I’m not opposed to entertainment; it’s just something I’m not interested in. No pejorative judgement is implied if you like entertainment. Read full post
-
Battle for Your TV: The Big TV Smackdown at SXSW
I made bad choices for the first two time-slots at SXSW, so I had high hopes for the third, PayTV vs Internet – The Battle For Your TV, featuring Mark Cuban of HDNet and Avner Rosen of Boxee.
It was good to see a debate between two people who genuinely disagree by 180º on how the future of TV will pan out, even if some of the argument was basically dick-swinging.
Cuban believes that the future of TV is basically the same as the present: subscription services over cable or satellite, with a light dash of so-called ‘Interactive TV’. Rosen believes, as I do, that the future of TV is on the web. To be clear: everyone sane accepts that we will continue to have a dedicated large screen in our houses on which we watch video. I just don’t believe that broadcast TV has a future that looks anything like the present, if it has one at all.