The Register® — Biting the hand that feeds IT

How I wrote an iPhone application

Michael Compton

Not sure who u will piss off more 

Java or Mac fanboi's, i think i can hear their foot steps coming in the distance, no wait its my team lead better start to look busy....

Stuart Gray

Ah! A blast from the past 

In the spirit of the "retro" PET article, finally a code listing that we can type somewhere, and then wonder why it doesn't work. Do we get a "corrections" section in next month's issue?

Dan

Useless? 

Thumb Up

This removes all references of the iphone from el reg - what's useless about that?

Anonymous Coward

Not just Safari 

This also works fine using Opera. (It works on 9.24 under Linux anyway). I tried it yesterday to see what would happen and was most delighted when all mentions of the iPhone changed to 'crock of shite'...

Paul

A+ on Java Script... 

F on HTML. WTF did you do? The page is a mess. Youve removed the %ages somehow! It may be somthing else, but I cant be botherd to surch your sorce code. It is hell to read.

Matt Horrocks

Nice 

Works on Opera under Windows too, although (surprise surprise) not IE7 (although I'm sure you could persuade MS to add functionality in if they know it's being used to have a dig at Apple). Nice to see it reported as the "SHiTEphone" after running the app :-)

Shakje

@Michael Compton 

Jobs Horns

Javascript isn't Java, and the Javascript fanbois are already pissed off because it's awful. Hopefully the Mac fanbois will already be just as pissed off because the iPhone is awful.

this

mile wide 

article aside, why does it not wrap in my browser (the article, that is) - its about 2 screens (1024) wide? Someting to do with all the javascript you've put there? weird.

Howie

Utter tosh 

Perhaps someone at El Reg who does not think that JavaScript is 'an annoying scripting language with aspirations of objecthood' should have attempted this task. This article seems to be a bitter stab at what the author considers a weak language, rather than an insight into builidng iPhone apps.

Having read to the end, it is clear that the author is unwilling or incapable of learning what is in-fact a very powerful language. I've not yet written an iPhone app, but if I did, I'm sure I would not need to use iFrames in my HTML markup, nor worry about page onload events, or the XmlHttpRequestObject. I'd use one of the popular JavaScript frameworks to do the plumbing - JQuery, Prototype, Dojo, and get rid of those global variables and functions.. maybe even use objects.

Bill. Stick to being a journalist. You're clearly not a developer. Mind you, based on this article, I'm not sure which you are worse at

Steve

Worked on the N95 

Thumb Up

It worked well on my N95, and I was tickled with my preferred moniker of sack'o'shite... :)

Alain Moran

Back button 

IIRC, you should be able to address the back button issue by altering the window.history Array, as for the onLoad issue, search for the </body> and inject a <script>parentFrame.doOnLoad()</script>.

Anonymous Coward

XMLHttpRequest is a cross-browser standard 

Thumb Down

"XMLHttpRequest doesn't exist anywhere else"

You know, a simple Google search would have saved you from writing obvious nonsense.

http://en.wikipedia.org/wiki/XMLHttpRequest

Lyndon Hills

Firefox 

Works on FF too although the layout isn't quite right.

Michael Compton

@ Shakje 

You are most correct my pedantic friend and I stand corrected :) *tongue in check humour, no offence intended* :)

Though they are close enough for me not to particularily like either. Just personal preference though, more a desktop programmer than web, in the immortal words of BG 'it will never catch on' :).

yeah, right.

Half works. 

Well, your lovely app seems to work with Safari on a Mac, but it completely fails in Firefox. Although why you'd write applications for the iGorilla is beyond me.

Ian Michael Gumby

And how is this an iPhone app? 

Thumb Down

I'm sorry if I'm being a bit of an old school kind of guy, but please someone explain to me how writing a javascript web page being an application which is loaded on to your iphone?

Did the definition of an application change when the IT press monikered web 2.0?

Not that I'm being critical of this little "hack" (again old school reference...)...

Matt Bradley

I'm sure I'm not missing the point here when I say: 

Joke

<?php

$change_to = $_GET['change_to'];

$fp = fopen([document]);

$document = fread($fp , 10000000);

fclose($fp);

echo preg_replace("\biphone\b/i" , $change_to , $document);

?>

... and you don't have to have bloody iPhone either.

Drew Cullen

Re: Any 'Developer' Jobs going at el reg 

(Written by Reg staff)

James, you seemed to have skipped over the first paragraph.

Bill Ray is a hack, not a hacker. Our software developers will arm wrestle you any day.

Anonymous Coward

Any 'Developer' Jobs going at el reg 

Thumb Down

Hmm, doesn't know anything about XMLHttpRequest

Doesn't understand that Javascript does have objects and is a powerful prototype based language (although with many issues!)

Uses javascript global variables

Can't write a valid HTML page.

Uses 'old school' event handling

How much do people on this site get paid to write 'web apps'? I can do a lot better than this and I'm pretty woeful :-) Please let me know how much my salary will be

Daniel B.

Javascript "language" ? 

Flame

"it is clear that the author is unwilling or incapable of learning what is in-fact a very powerful language."

I reel in shock from the sudden IQ loss. All I have to say about JavaScript is what Joe Buchanan said about Frankenstein's Monster: "It's an abomination in the eyes of God".

Instead of dying as it should have, some wise-crack decided to "mate" the damn thing with Web Services, which were NEVER meant to be used by end-users, but instead for B2B EDI transactions, and create the AJAX "technology". Urggggh...

That said, its a useful app 'coz it blocks "iPhone" and its source code shows how shite the Javascript "language" is!

I prefer server-side Java (J2EE) or even client-side, as it'll run independently of your browser or OS.

Anonymous Coward

@Javascript "language" ? 

Stop

> I prefer server-side Java (J2EE) or even client-side, as it'll run independently of your browser or OS.

Right, because I really want to have to load an external VM and suck down huge quantities of memory and CPU cycles just to have a little interactivity on my web forms. On a mobile device even. That'll be sweet.

Seriously, yes Javascript has its fair share of problems - probably more than a lot of other common languages - but if you really think its object model is weak then you're doing it wrong. Go read a book - hell, a web page - and come back when you know something about the subject.

daniel

@By Daniel B. 

Flame

Amen Brother.

The app can't even work consistently across versions of Safari, let alone play nice with IE and Opera!

Do everything server side and render nice HTML. A shame that javascript was never replaced by a client side equivalent of Java or PHP with access to the browser DOM....

Robert Grant

JQuery 

Let me emphasise something an earlier commenter mentioned.

Use JQuery.

JQuery.

Don't not use JQuery.

http://jquery.com.

From someone who's happy that JQuery makes Javascript into a language that looks as though it was designed to interact with the DOM (CSS3 selectors, no less), rather than one that looks like Java, which clearly was not designed for this task.

Martin Budden

GreaseMonkey? 

Boffin

Sounds to me like your app does the sort of thing GreaseMonkey is very good at. If you could turn your app into a full GreaseMonkey thing, it might actually become popular.

Ascylto

Wake me when it's all over ... 

ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...................

Stephen

I know I am going to get flamed for this but... 

Dead Vulture

...I don't care.

Your article was, quite frankly, poor. You clearly did NOT research your subject matter before posting, somthing which is becomming more and more prevelant across dead reg.

The code is an abomination, whilst I won't get drawn into the JavaScript is shite debate (it is shite, but I have no need to qualify that statement) you could/should have at least made sure your code works properly. For a start it is possible to do what you have done on ANY half modern browser, any good developer of web based systems knows to make crosss browser capabilities a priority. But, your not a developer.

Once again a register posting that could have been somthing usefull, let down by lazy 'reporters' who have about as much IT knowledge as a cabbage...sort it out or close down.

stumbo

what has this gota do with an iphone ??????? 

Thumb Down

This is a beginners guide to a javascript webpage. Thats it {shrug}

This has as much to do with an iphone as it does Windows CE, WML etc.

But then is that meant to be web-2.0 ironic ???

jubtastic1

hmm 

Stop

Here's a useful resource for anyone that mistakenly thought this article would be useful for anything other than starting fires: http://groupaware.mobi/iphone/#_Samples

Henry Wertz

@M Gumby and anon. 

Paris Hilton

Believe it or not, Jobs and Co. have actively tried to break any and all hacks letting people install their own software onto their own devices with each new firmware release. Despite Apple fans calling it a smartphone, it is not -- the end user cannot install their own apps. Apple's official method to write apps "for" the iphone is to do javascript, html, ajax, etc.

As for XmlHttpRequest, on paper it's standardized. In practice I keep reading about people having to throw in hacks to make it work properly on various browsers.

Robert Forsyth

Works in Konqueror 

Thumb Up

which might not be too much of a suprise.

Snags:

The buttons in the bottom frame are a bit over sized, and the couple of second delay while nothing happens.

Forums

Password reminder

Sign up, sign up for The Register's weekly mobile & wireless newsletter - click here