www.richardhyland.com ..::.. richard’s diary

web developer : windows developer : amateur photographer
  • rss
  • Home
  • Diary
  • Photo Collections
  • Personal Gallery
  • Contact Me
  • NewsSeeker
  • Dominion Web

Some cool tips and tricks for the iPhone SDK

21st December 2008

During the course of developing my latest iPhone application (currently awaiting approval from Apple) I solved a number of issues I’ve had in previous attempts but I’ve finally solved them.  Apologies to anyone reading this that thinks, derrr I’ve known this for ages, but hopefully it’ll help some developers with their iPhone applications.

1) Updating the main UI from a thread.

If you call a function using a thread

[NSThread detachNewThreadSelector:@selector(getXML) toTarget:self withObject:nil];

then you might want to update the main user interface e.g. to display a status on a toolbar.  Well as it turns out the thread is protected and can’t access the main ui whilst the thread is running.  The way to solve this is using the following code

[self performSelectorOnMainThread:@selector(updateBadge) withObject:nil waitUntilDone:NO];

where updateBadge is a function.

2) Changing a refresh button to display a UIActivityIndicatorView on a toolbar
Let’s say we have a toolbar at the bottom of the screen and we’ve added a refresh button e.g.

UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(actionRefresh:)];
refreshItem.style = UIBarButtonItemStylePlain;

NSArray *items = [NSArray arrayWithObjects: flexItem, refreshItem, nil];

[toolbar setItems:items animated:NO];

Then by default with that code it would display a refresh button at the right hand side of the toolbar, and when clicking on it would call refreshAction:(id)sender.  To be helpful to the end user we might want to change the refresh button to an activity indicator whilst the refresh action was taking place.

The first job is to make the refresh button and flex item a global property so you can call them from different place.  Now we also need to create a UIActivityIndicator.

When the refresh action starts you can call the following code to display the activity indicator

CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[loading sizeToFit];
loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);

[loading startAnimating];

UIBarButtonItem *statusInd = [[UIBarButtonItem alloc] initWithCustomView:loading];
statusInd.style = UIBarButtonItemStylePlain;
NSArray *items = [NSArray arrayWithObjects: flexItem, statusInd, nil];
[toolbar setItems:items animated:NO];

Then when the refresh action stops, simply call the following, as we’ve already made flexItem and refreshItem a global property we don’t need to redefine them or re-point them to their action selector.

NSArray *items = [NSArray arrayWithObjects: flexItem, refreshItem, nil];
[toolbar setItems:items animated:NO];

3) How to display an application badge
Now of the three items I discovered this is probably the easiest and it simply the code you need to display the little red badge icon, like the one you see when you have unread email on the mail icon on the home screen.

[UIApplication sharedApplication].applicationIconBadgeNumber = 10;

To hide the badge simply set the value to 0

Share/Save/Bookmark

Comments
No Comments »
Categories
iPhone
Comments rss Comments rss
Trackback Trackback

The dilemma of iPhone Apps

6th December 2008

I’m sure other iPhone developers have come up against the same dilemma as me, you come up with what you think is a great idea for a new iPhone Application to perform a quick search on the iTunes App Store and discover that 5 other people have done the same thing.  So the dilemma, do you still write the app because you think you can do better, or do you think of another idea?

Well so far I’ve developed one that I came up with the idea and the same day it got published two others of the same subject did.  For the second idea no one had written an app on this subject yet.  Yet when I came to submit the final code there were three, yet I still submitted because I’d spend enough time working on it.

Now the second dilemma, I’ve got another idea, which obviously I won’t share until I’ve completed it, but do I actually bother as at the time of writing, no one has done this yet, but will they have done by the time I finish coding the application.  Although it will probably only take a fortnight to code.

Heck I’ll probably write it anyway… watch this space!

Share/Save/Bookmark

Comments
No Comments »
Categories
iPhone
Comments rss Comments rss
Trackback Trackback

The simply amazing MacBook Air

Unlike many teccys, I’m neither in the Windows, Mac or Linux camp.  I’m actually in all three.  I love using Linux for web servers, they are simply the best operating system in my opinion for running PHP, MySQL and Apache (otherwise known as LAMP).

I also love Windows Vista.  Controversial some might say, however I have NEVER had a single issue with Vista and it works fantastically for me, it looks great as well!

Now onto the Apple Macs.  My history with macs is both relatively recent and actually quite old at the same time.  I can remember as a kid, my dad bringing one of the early Macs home from work and me playing with the drawing tools.

Now my first mac was an iMac Snow, one of the old CRT screens all in one with a CD drive, running OS X 10.2, then came an iBook G4, followed by a Mac Mini.

Then came the current iMac generation which interestingly also makes my most stable Windows PC to date due to the fantastic BootCamp.

Just before I went on holiday this year i finished my latest iPhone App, called iSki, which shows the snow fall and webcams for all the major ski resorts in the world.  I submitted it to the App Store the day before I left, knowing that it usually takes Apple about a week to two to approve initial submissions of new Apps.

At the end of the second week, the App was rejected due to minor issues and I knew could be fixed in seconds and resubmitted.  

How does this relate to the MacBook Air? Well if I had a Mac with me I could have fixed this issue, resubmitted within minutes rather than waiting a week to get home and then a further week to get it approved (which actually it was).

So the answer for me was either the MacBook or the MacBook Air?  The MacBook is cheaper and more powerful but the MacBook Air is incredibly small and very light.  I almost got a MacBook until I remembered the entire reason for the purchase… portability!  Then I remembered the Apple Refurb Store.

The rest is history, I’m now typing this on my Air and it’s a wonderful bit of kit, if I’d have wanted a desktop replacement I’d have gone for the MacBook Pro, for the portable work system, the Air wins on so many levels for me.

Share/Save/Bookmark

Comments
No Comments »
Categories
Computers & Internet
Comments rss Comments rss
Trackback Trackback

The recession will be over in…

27th November 2008

 This has got to be a laugh, our illustrious leader has decreed that the recession will be over in the 3rd quarter 2009. Let’s keep track shall we?

Share/Save/Bookmark

Comments
No Comments »
Categories
Politics
Comments rss Comments rss
Trackback Trackback

How to get a Wii Fit the easy way

26th November 2008

So last year it was the Wii console that was impossible to buy, now it’s the Wii Fit.

What is it with the UK having a lack of stock of just the thing everyone seems to want.  Well it seems Germany and France have loads of them.  You can buy them from Amazon France and Amazon Germany and have them shipped to the UK for cheaper than most UK retailers are selling them.  This website even gives a step by step guide on how to order it!

Share/Save/Bookmark

Comments
No Comments »
Categories
Games
Comments rss Comments rss
Trackback Trackback

Great video about the great economy cover-up

31st October 2008
This is the first of 5 videos I found on YouTube from someone called The Renegade Economist, uncovering the people and practices behind the global financial crisis.

Share/Save/Bookmark

Comments
No Comments »
Categories
Politics
Comments rss Comments rss
Trackback Trackback

I’m on Twitter

30th October 2008

I’m now on Twitter, lots of people seem to constantly talk about it, I still don’t really see the point in it but I’m going to give it a go and see whether I like it or not.

In the mean time you can follow me, although I will not promise that it’ll be exciting or informative, here.

Share/Save/Bookmark

Comments
No Comments »
Categories
Computers & Internet
Tags
twitter
Comments rss Comments rss
Trackback Trackback

myTube for the iPhone

1st October 2008
What is myTube?: Information and navigation of the London Underground network.

Highlights:

  • Tube Status: browse the latest tube status updates, including DLR. Change the look and feel from pre-defined skins.
  • Map: view the London Underground map live on the TfL website and optionally download and save the map to your iPhone for viewing offline
  • Nearest Station: find the nearest Tube or DLR station from your current GPS location, distance and directions over ground
  • Route Planner: whilst overground just select your starting station, your destination and find out how to get there including line changes, then view that route whilst underground
  • Navigation: how to get to or from a Tube station using an address or post code
  • Tourist Attractions: Find attractions near to stations and how to get there overground

This application is designed for usage in connection with the UK London Underground network.

Because of TfL copyright we cannon bundle the Tube map for offline browsing with the application itself. When you use the map it will use the one on TfL’s site, however you can optionally download and save the map for viewing without an Internet connection.

This Application is available from the iTunes App Store.

Share/Save/Bookmark

Comments
No Comments »
Categories
iPhone
Comments rss Comments rss
Trackback Trackback

iPhone development

1st September 2008
Xcode icon

Xcode icon

I’ve developed in a number of languages and systems over the years from Windows Batch Files, Perl, PHP, C#, VB, ASP, etc, etc and I absolutely love Visual Studio 2008 and it’s intellisense.

Now I thought I’d dab my hand at iPhone development.  For those that don’t know you have to use a Mac OSX application called Xcode to be able to develop for the iPhone and iPod touch, and then using this in a language called Objective C which seems to be Apple’s own extension to C and C++.  To be honest I’ve never gone down the C++ programming route and it probably wouldn’t have been so difficult had the Apple Developer Documentation been any good but basically before Apple lifted their NDA and allowed discussion about developing for the iPhone it was basically trial and error which insanely cryptic compiler debug errors.

Anyway I’ve solved many of the issues now and coming next I’ll talk about my first App that’s already on the iTunes App Store.

Share/Save/Bookmark

Comments
No Comments »
Categories
iPhone
Tags
iphone programming objective-c
Comments rss Comments rss
Trackback Trackback

Finally browser companies take the lead in XSS

3rd July 2008

My RSS reader popped up with a new article from the IEBlog today, for those that don’t know the IEBlog is the web log from the Microsoft Internet Explorer team.

The article is over at http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx detailing that Internet Explorer 8 Beta 2 will include a Type-1 XSS Filter.  This is fantastic news as along with phishing and nigerian 419 scams, XSS attacks are an evil crime designed to simply steal user’s personal information or money.

Sure us developers should make sure we never make websites vulnerable to XSS scams but that doesn’t excuse people actually using XSS to steal information.  Heck even PayPal recently had an XSS vulnerability.

Well now finally the web browser manufacturers are going to start protecting users who don’t have enough knowledge or even need to know anything about XSS.

Share/Save/Bookmark

Comments
No Comments »
Categories
Computers & Internet, Security
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Pages

  • About
  • Archives
  • Contact Me
  • Dominion Web
  • Masai Mara 2008
  • My Amazon Wishlist
  • NewsSeeker

Categories

  • Animals (8)
  • Christmas (2)
  • Computers & Internet (17)
    • iPhone (4)
    • Security (1)
    • Web Development (2)
  • Drink (1)
  • Entertainment (1)
  • Food (1)
  • Friends (2)
  • Games (1)
  • General (12)
  • Home (1)
  • London (7)
  • Music (4)
    • Bon Jovi (1)
  • Nature (3)
  • Personal (2)
  • Photography (16)
  • Politics (2)
  • Travel (10)
    • Egypt (1)
    • Kenya (6)
      • Safari 2008 (6)
    • Safari (4)
  • Weather (1)
  • Wedding (2)

Hot Topics

Animals Bon Jovi Christmas Computers & Internet Drink Egypt Entertainment Food Friends Games General Home iPhone Kenya London Music Nature Personal Photography Politics Safari Safari 2008 Security Travel Weather Web Development Wedding

Follow me on:
Follow me on Twitter

Computers & Internet

  • Apple UK
  • Channel 9
  • DWmail
  • NewsSeeker
  • Scobleizer
  • XBox.com

Favourite Sites

  • Beth John
  • Digital Spy
  • Dominion Web
  • My Facebook
  • WWE

Politics

  • Benedict Brogan
  • Boulton & Co
  • Dizzy Thinks
  • Iain Dale’s Diary

Calendar

January 2009
M T W T F S S
« Dec    
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

  • December 2008 (3)
  • November 2008 (2)
  • October 2008 (3)
  • September 2008 (1)
  • July 2008 (2)
  • June 2008 (1)
  • April 2008 (2)
  • March 2008 (2)
  • February 2008 (3)
  • January 2008 (7)
  • December 2007 (1)
  • August 2007 (4)
  • July 2007 (2)
  • June 2007 (6)
  • May 2007 (8)
  • April 2007 (2)
  • March 2007 (2)
  • February 2007 (2)
  • January 2007 (2)
  • December 2006 (5)
  • September 2006 (1)
  • August 2006 (3)
  • July 2006 (2)
  • May 2006 (1)
  • January 2006 (1)

XBOX Live Gamer Card

Facebook

Richard Hyland's Facebook Profile
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox