Posts Tagged ‘iPhone’

My first iPhone / iPad apps

August 25, 2010

Here’s a long overdue post. Below you will find links to two iPhone / iPad applications developed by yours truly.

As you can probably guess I am hoping to add more books in the series when i find the time.

Sales hasn’t exactly shot through the roof, with on average one to two copies a day.

How to terminate iPhone application from code

June 18, 2009

Today i had to terminate an application, if certain launch conditions where not met (settings not filled out more specifically). I started out searching for information regarding UIApplication, but it turned out that a simple C call does the job: exit(0);

Update: As is pointed out in comments, there seem to be some content as to wether explicitly exiting an application will result in failure to pass the Apple AppStore aproval process.

In my case i was building a pure online app. If no connection could be established on startup, the user would be presented the option to retry or cancel. Cancel would result in the app exiting. Pretty rutine behavior, but I guess I could just remove the cancel button and leave it up to the user to use the hardware button.

In light of the new information then, the proper recommendation has to be do not terminate apps explicitly.

iPhone SDK: Show address in Google Maps

February 17, 2009

As a part of the project i am currently working on (seems there is a difference between finished and FINISHED), i had to implement the pretty standard feature of displaying an address in Google Maps. To my suprise it took me quite some time to find the code, so to make things easier for others, i thought i would post it here.

If found a demo app (http://www.appsamuck.com/day3.html) that shows how to use multiple different url types (phone, email, etc.). At a glance it worked fine, but when i tried to open a Danish address with special characters (æ, ø, å), the “address” bar in Maps would just read “null”. It turned out that who ever put together the sample app, used NSASCIIStringEncoding as the format for encoding the spaces in the address – in my example i changed it to NSUTF8StringEncoding. Enjoy:

// Where is Apple in Denmark on the map anyway?
NSString* addressText = @"Nørre Voldgade 11, 1358 København K";
// URL encode the spaces
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Combine url
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
// Open url
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

Add entry to contacts using iPhone SDK

January 18, 2009

So i recently started programming for iPhone. As part of the project i’m currently working on, i have to add new entries to the phones address book (contacts). The address book api is not very intuitive, seems to be a straight C api and is poorly documented. It took me a lot of googling to find the solution, so i promissed my self i would post the code once i found it .

(more…)