Archive for the ‘Computers & Internet’ category

User Location and your own annotations in a MKMapView

August 1st, 2011

I’ve spend a while working this one out.

For a long time I’ve had a MKMapView to display pins dropped in specific places on a map.

I’ve done this through the delegate method

-(MKAnnotationView *)mapView:(MKMapView *)mapView  viewForAnnotation:(id) annotation {
  MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
 // Some customisation goes here
 [annotation autorelease];
 return annotation;
}

That’s all very will but then I decided it’d be nice to show the user’s current location on the map as well, you know the lovely blue pin with accuracy circle around it.

Well enabling this looks very simple.

mapView.showsUserLocation = YES;

Now I have custom objects in my annotation subclasses so I can reference them easily later. With this, however, if you compile and try to run, when the view loads you’ll get a crash with this error to the debugger.

-[MKUserLocation getTagId]: unrecognized selectory sent to instance

It turns out the way to get this to work is to include at the top of the delegate method the following line

if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;

Compile and run and all will work fine

Why the iPad 2 will have a 2058×1536 resolution

January 21st, 2011

Let me take you back to the old iPhone 2G, 3G and 3Gs. This device had a screen resolution of 320 pixels wide by 480 pixels high.

Developers were explicitly told to code for that resolution and did so with great success. This immediately raised a concern for me, what would happen in the future, when Apple would release a new device with a higher resolution, something they surely would?

Well along with many other iPhone fans we heard the keynote from Steve Jobs announcing the Retina display for the iPhone 4. This had a resolution of 640×960. It left a number of people, developers, etc wondering how they would support both the existing iPhone and the new iPhone 4 in their apps.

As I wrote in a previous post, Apple actually pulled off something very remarkable and very clever with the Retina Display.  They kept the screen ratio exactly the same, and made the screen exactly twice as big.

Assets in iPhone applications not ‘Retina Compatible’ simply had all of their graphical assets doubled up in size.  320 pixels wide became 320 points wide and so on.

How did a developer support the retina display, why they simply added an image of the same ratio, but exactly doubled to their app bundle but instead of a .png extension they added @2x.png to the end of the file with the same name.

It was incredibly simple to implement and required zero code changes whatsoever.

iPad 2

The iPad has a resolution of 1024×768 which does look amazing but unfortunately for the iPad, the iPhone 4′s Retina Display was released only slightly after the iPad.

Now there has been lots of commentary as to what the resolution would be on the iPad 2, would they simply increase it slightly or would they change the ratio, etc.  There are commentators stating that a resolution of 2058×1536 would be very unlikely due to memory requirements.

In my personal opinion, it’s actually incredibly unlikely we will see any other resolution other than either keeping the status quo of 1024×768 or going for 2058×1536.

If Apple were to release an iPad with a different screen ratio or not @2x, existing iPad apps would not fit the screen properly.

People will argue but Windows and OS X apps don’t worry about this, no they don’t but then they also weren’t explicity told your only option is to provide a full screen application like iOS developers are.

Apple could scale these, but from experience of using iPhone applications on the iPad, scaling tends to look terrible.

The reason I believe 2058×1536 is likely, is first it has been found in the iOS 4.3 beta’s a number of iBook image assets with the @2x extension and are exactly doubled, but also that Apple can apply exactly the same logic as they did for the iPhone 4 and developers will have an option to support the new display or not without adversely affecting the layout of their App.

Additionally if we don’t have a double resolution we end up with the exact same type of fragmentation of iOS that Apple complains about the Android ecosystem.

Could it be called ‘Retina’ as the pixel density probably isn’t high enough, well I don’t know.

* Image credit Glenn Fleishman

Custom Logging in Obj-C

December 7th, 2010

If you’ve used Objective-C for Mac or iOS development you’re probably familiar with NSLog(); to log to the console.

Well that is fantastic for development, but you don’t really want to output your debugging logs on distributed iOS apps do you?

It would be a real pain to remove every instance of NSLog from your code everytime you wish to distribute your app.  Well you can solve this with a custom logger.

In your Prefix.pch file add the following bit of code

#ifdef DEBUG
#  define RHLog(...) NSLog(__VA_ARGS__)
#else
#  define RHLog(...) ;
#endif

Then whenever DEBUG is set (either by adding DEBUG to your pre-processor macros, or using the -DDEBUG flag) instead of calling

NSLog(@"String: %@", stringValue);

you can call

RHLog(@"String: %@", stringValue);

And when in debug mode the string will log to the console, in Release, Ad-Hoc and Distribution builds it won’t

However you can go one further than this and actually produce a much nicer logging function using

#ifdef DEBUG
#   define RHLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define RHLog(...)
#endif

and when you call your function like so

RHLog(@"Testing");

You’ll see the following in your console

-[AppDelegate startup] [Line 123] Testing

* Image Credit Fryhstyxei

The iPhone App Piracy Problem

August 18th, 2010

The iOS (that’s the iPhone, iPad and iPod Touch) AppStore has a problem.

A piracy problem.

If you have a jailbroken iPhone, that is one where you have run a bit of software to allow you to download apps outside of the AppStore then you may have come across pirated apps, you may not have installed them but you’re probably aware of them.

Before I talk about the morality of piracy, let me address the question of why

Why do pirates crack apps?

This is an interesting question and to understand the piracy we must address the motivations

1) Try before you buy

I’ve heard this many times for people’s justifications as to why they crack apps.

Apple doesn’t offer any form of demo or free trial for Apps and so I can understand this motivation.  However there are two problems with this justification

  1. Many of the popular apps already provide a ‘try before you buy’ in the form of a free ‘lite’ app from the App Store itself
  2. The conversion rate from cracked to paid is less than 0.5% (source)

The conversion rate of cracked to paid is incredibly low which simply blows any form of arguement of try before you buy out of the water… it’s total rubbish.

Sure some of you out there have done so, and I applaud you for that, but unfortunately you are in the very small minority.

2) A hatred of DRM

DRM (or Digital Rights Management) is an encryption and licensing technique used on DVD’s, BluRays, some iTunes purchases, etc and Apps from the AppStore.

It’s a system, whether you like it or not, that restricts where you can and can’t install your purchase. How many times you can install it and then what you can do or modify in it once you have installed it.

Cracking an App on the iPhone removes this encryption and DRM.

Again I can understand this, if someone wants to remove the DRM and encryption for their own use, then for me this is fair enough and I have no problem with them doing this.

But how, I ask, did that app end up on file sharing sites and specialised cracked app repos.  Opps sorry you’ve lost your argument again.  The minute you share that DRM free version you’ve lost my respect again and you’ve breached my copyright.

3) A fundamental belief that software should be free

This is the last category and it’s either that the user has a belief that all software should be free or they simply don’t care about the law.

The former, is a belief that a number of people hold, however who are they to decide under what license my software should be released.  Did they write it? Do they own the copyright? NO they don’t. So they do NOT get to decide under what terms my software is available.

If they want to write their own software and release it for free I will defend their right to choose that path, but at the same time I will defend anyone who decides to charge for their software, as it is their right to do so.

The rights of a developer

A developer works, a developer has a family, a developer has a mortgage, a developer has taxes to pay, a developer has computers to purchase to develop on, a developer has software to purchase (developers don’t use pirated software to develop commercial software, that would be hypocritical wouldn’t it!), a developer has servers to license, domains to buy, food to put on the table.  Do you see where I am going with this.

That push notification feature you love, that scheduling feature you love so much.  A server is involved there and who pays for that? Well either the developer makes a loss paying for it, or legitimate customers have to pay more simply to cover the cost of you giving away the app for free.

A cracker in all likelyhood isn’t a developer, they probably have a job outside IT.

Think about it this way, if you work in an office and an intern comes in and claims credit for all your work and doesn’t get paid, but because they’ve claimed credit for all your work you don’t get paid either, in fact you get made redunant is that fair? Is that right? No of course it’s not.

Developers do not work for free, they have the same bills and financial outgoings as anyone else.  So a message to the app crackers who distribute cracked apps out there, what gives you the right to give away my software for free and prevent me from paying my mortgage this month? ABSOLUTELY NONE, you are thieves… end of story.

How to harness the Retina Display in your app

July 15th, 2010

It is remarkably easy to do so and I implore all all iPhone developers to please upgrade all their apps to support the Retina Display on the iPhone 4, otherwise your app just looks blurry.

What Apple achieved with the Retina Display is a remarkable feat. The screen is still exactly the same size of 3.5 inches but where you used to have 1 pixel you now have 4. This means UI elements are scaled exactly by 2.

Developers were always told to design for a screen resolution of 320×480 pixels, so don’t I need to change my UIViewControllers to have a different size?

Well no, and this is how Apple have been incredibly clever. The screen dimensions are now 320×480 points, and not pixels so in your UIViewController you still have the size 320×480. With me so far?

Images

Ok so lets say I have an image that needs to span the width of the screen and is only 100 pixels high on an iPhone 3G or 3Gs we simply embed an image of 320pixels by 100pixels. So that image that we’ve called banner.png, for example, looks perfect on those old devices but they look blurry on the iPhone 4.

I can hear you asking, if the screen is 320points wide but is actually 640pixels wide, how do I provide both an iPhone 4 and iPhone 3G(s) version of this and how much code does it take.

Well my answer is, very easy and zero, that’s right, zero code modifications.

Now you did have a high resolution, or vector version of your artwork right? Ok well open it up and scale it to exactly double the size of the original file. So you’ll now have an image that is 640×200 pixels and save it as banner@2x.png (as the original was called banner.png). Add the new image to your resources in your XCode project.

You can call your image in exactly the same way as before

UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,100)];
[myImage setImage:[UIImage imageNamed:@"banner.png"]];
[self.view addSubview:myImage];
[myImage release];

When you run your app on your iPhone 4 (or the iPhone 4) simulator the image will magically use the banner@2x.png version instead. Clever isn’t it!

Default splash images

This is exactly the same as for images, just include a Default@2x.png image in your bundle and the iPhone 4 will use it instead.

Springboard App Icon

Ok now this one is a little more complicated, but not by much. If you’ve already designed a Universal (iPhone and iPad) app then you’ll be familiar with this technique, and actually there are a couple of ways to do it but I’ll explain the one from the Apple Docs.

If you want to still provide support to iOS 3.1.x and below you’ll still need a

CFBundleIconFile

with Icon.png in it for your Info.plist but you should now also include an array entry of

CFBundleIconFiles

Include an Icon.png file, this is your non-iPhone 4 57×57 file
Include an Icon@2x.png file, this is your iPhone 4 114×114 file.

Yep once again it really is that simple.

Conclusion

If you have an app that simply uses SDK UI Elements and/or images, which the majority of iPhone app do, then you simply have no excuse not to support the Retina Display… so what are you waiting for, go cut graphics and submit!

Apple’s iPad UK pricing

May 8th, 2010

I’ve read a lot of comments online since Apple announced it’s international iPad pricing, and most of those comments revolve around ‘Rip-Off Britain’.

Now it is true that must tech imported from the USA seems to cost more with this mythical international tax and at first glance the iPad pricing in the UK is a lot more but let’s break it down for the 16Gb WiFi iPad.

In the US this is $499. The UK price announced is £429.  At a direct comparison at today’s exchange rates of 1.48, that comes to $648.  Wow that seems an awful lot more.  However that simply isn’t a fair comparison.

In the US all prices exclude sales tax which our friends in America accept is always added at point of sale and calculate the price in their head all the time.  In the UK we have VAT so the tax is always added (and at the moment it’s 17.5%).  So let’s take off the VAT from £429 and it comes to £365.

Convert that to USD and we see the UK iPad price is actually $540.  So the UK iPad is actually $41 more expensive in the UK than the US… that’s a whole £27, although yesterday it was £25.

I’m sure there are some import taxes or costs and £27 more isn’t really a lot of money, sure I’d prefer not to have to pay it but it isn’t what I’d call rip-off Britain compared with the US price.

If anyone is to blame it’s the level of VAT we get charged in the UK.

If we compare our £429 iPad with VAT to what it costs, in say California with federal and local sales tax of 10.75% we see that in the US the iPad costs $552.64 which is £373.

So the entire reason we feel we are being ripped off for our technology is nothing to do with Apple in this case and everything to do with the Government and our VAT.

Of course importing it isn’t a solution either, because you did remember to pay your VAT when it came through customs didn’t you?

Apple’s delay to international iPad shipping and how it harms developers

April 14th, 2010

Apple has today announced that they are delaying international shipping of the iPad until the end of May.

As a user, and future owner of one of these devices I’m disappointed.

As a developer, I’m angry and let me explain why.  International developers are now at a severe disadvantage to US based developers without great expense to themselves, of finding a way to import the iPad from the USA.

US based developers have been able to see how their app looks, feels and works on a physical iPad whilst those of us not in the US have only had the simulator which is simply not good enough.  Anyone who has developed anything more than a one screen app for the iPhone will know that the simulator often behaves differently to the ARM architecture of the iPhone itself.

I’m not asking for Apple to give developers discounts, special advance access, free shipping, etc.  All I am asking is for Apple to allow a level playing field for developers and so that international developers that have PAID to register in the iPhone Developer Program should have a way of gaining access to the devices to be able to develop and test on.

At the moment there is no fair playing field between developers in the US and those of us who are not, of which I wouldn’t be surprised if there are more outside the US than in it.

Robert Scoble has written a great blog post on why Apple’s prediction was so wrong.

Creating a mini map using MapKit on the iPhone

November 20th, 2009

So as promised here is the final part of my MapKit tips and tricks using the iPhone SDK.

Sorry it’s a little later than I intended as I wanted my version of the feature live in the AppStore before I published the article.

So we’ve seen before how to create a simple map, well now let’s see how to create a really small thumbnail sized version like this (sorry there is no anti-aliasing, the iPhone simulator doesn’t support it on MapKit, works fine on the actual device though!)

smallmap

In my version, I take this code and add it to a much larger view controller like this

bigmap

A bit of shameless plugging: this comes from Tweetings for the iPhone

I won’t cover anything more to this other than getting the map to a state where you can add it to any view of yours using the [object addSubview:mapView] call.

Generating the map

This is the same as generating a large map, that we’ve covered before, except the frame will be of a different size, however the most important factor here is we are going to scale the map

float scaleBy = 0.80;
MKMapView *mapView = [[[MKMapView alloc] initWithFrame:CGRectMake(-5, 0, 100/ scaleBy, 50/scaleBy)] autorelease];
mapView.delegate=self;
mapView.layer.cornerRadius = 10.0; // Make the corners rounded
mapView.opaque = NO; // If you are using in a UITableView never set to YES!
mapView.scrollEnabled = NO; // Don't allow user interaction
mapView.zoomEnabled = NO;
mapView.layer.borderColor = [UIColor colorWithWhite:0.0f alpha:0.5f].CGColor;
mapView.layer.borderWidth = 1.0f/ scaleBy;
mapView.layer.transform = CATransform3DMakeScale(scaleBy, scaleBy, 1.0);

At this point you can actually now add it to your view and set any other properties in the same way as you would normally, job done…. yes it really is that simple!

My take on Chrome OS

November 20th, 2009

So Google have unveiled Chrome OS… which in actual fact is just a web browser where all you can do is interact with web apps. This isn’t a review, in fact if you want that go to Engadget

It’s even less than a thin client of old (read: Citrix). When did we suddenly decide that thin clients were a good idea again?

I’ll just put one single thought and it was said by Marc Andreessen in 1995

“[Netscape will soon reduce Windows to] a poorly debugged set of device drivers.”

Yeah that went well didn’t it.