Archive for the ‘iPhone’ Category

Introducing APTokenField

April 1st, 2012 Comments off

Working on Line2, I wanted to emulate the message composition screen Apple uses in iMessage and in the MFMailComposeViewController class. Specifically, I wanted to emulate the ‘To:’ field so I could use it in the SMS message composition screen in Line2. At the time, the only option that met the need was TTPickerTextField (part of Three20). I finally bit the bullet and integrated it into Line2, but it had some drawbacks, the biggest being that you have to integrate all of Three20 to use it.

After awhile, I got an itch to remove my dependency on Three20, so I wrote APTokenField. A lightweight, stand-alone implementation of the TTPickerTextField functionality. First some pictures to show what it’s capable of:

APTokenField screen shot 1

APTokenField as used in its sample app

APTokenField screen shot 2

APTokenField as used in Line2

Let’s take a look at the available features:

  • You can specify a text label to be displayed on the left side of the token field.
  • You can specify a custom rightView, that does whatever you want it to do. Just set the rightView‘s bounds and assign it to the APTokenField’s rightView property
  • Support for multiple lines of tokens. Even when the number of tokens is large, the view scrolls up to let the user see the result set.
  • Easy to use in your parent view’s layout. No need to mess around with UIScrollViews. Just add it to your view hierarchy and set it’s frame to whatever size you want. The table of results will automatically hide when there are no results, and it will take up whatever area is available in the frame.
  • Everything is contained in two source files. No images required.

If you wanna jump right into it, head over to the APTokenField github page and clone away. Otherwise, here’s a brief tutorial to start using it.

  1. Add APTokenField.h and APTokenField.m to your project
  2. Add the QuartzCore and CoreGraphics frameworks to your project

Let’s take a look at the project in the APTokenField repo. It contains a controller (APTokenFieldController) and a data source (AmericanStatesDataSource).

The data source conforms to the APTokenFieldDataSource protocol, which lets the user search the 50 American states and add them to the field by tapping a result. The meat of this class happens in the four required methods, which search and return values from the array of American states. As the user types characters into text field, the -(void)tokenField:searchQuery method will be called with the current text. It’s up to you to decide how to implement your search, but for this simple example we just check if the search text exists in the name of any of the states, and if it does, the matching state gets placed into the results array. The table of results gets updated automatically in the UI, and you don’t have to make any complicated callbacks when you’re done (I’m looking at you Three20).

If you want to get feedback on when the user adds and removes tokens, you can implement the APTokenFieldDelegate protocol. If you wanna use a custom UITableViewCell for the results, take a look at the optional methods in the APTokenFieldDataSource protocol.

You should follow me on Google+.

Categories: iPhone, Open Source Tags:

Presenting, Appirater

September 7th, 2009 16 comments

Like most developers, I’m not thrilled with the way the App Store presents my apps. There are several problems, but in particular, I really don’t like the user review system. It’s biased towards bad reviews, and that ends up hurting sales (there are odd exceptions to this). The only time a user is reminded or asked to rate an app is when you delete it, and you probably don’t care for the app if you’re deleting it. In comparison to the unhappy user, the satisfied user rarely takes the time to review your app. Which leaves you with crummy reviews from uninformed users hurting sales of your app.

If Apple would allow developers to respond to reviews, or more easily challenge the validity of a review, this would be no big deal. But I don’t have any hopes of Apple wising up and fixing anything, so I’m left trying to get more positive reviews of my apps to drown out the negatives ones.

The goal of Appirater is to encourage your satisfied user’s to rate your app. To use it, place the Appirater code into your project, and add the following code in your app’s delegate class.

// import the Appirater class
#import “Appirater.h”

@implementationMyAppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// all your app’s startup code
    // …

// call the Appirater class
    [Appirater appLaunched];return YES;


Finally, open up Appirater.h and change the APPIRATER_APP_ID to your apps software id. You can also change the other #defines, for a more customized reminder message and buttons, but the default should suffice for most apps.

Now every time the user launches your app, Appirater will see if they’ve used the app for 30 days and launched it at least 15 times. If they have, they’ll be asked to rate the app, and then be taken to your app’s review page in the App Store. If you release a new version of your app, Appirater will again wait until the new version has been used 15 times for 30 days and then prompt the user again for another review. Optionally, you can adjust the days to wait and the launch number by changing DAYS_UNTIL_PROMPT and LAUNCHES_UNTIL_PROMPT in Appirater.h.

Appirater as used in Prayer Book app


BTW, if you like Appirater, please consider checking out my game, Jabeh or the lite version of it.

UPDATE: Ivan Nikitin has made a MonoTouch port of Appirater.

Cheap iPhone data plan with T-Mobile USA

August 25th, 2009 16 comments

Just a quick post for everyone who’s lucky enough to be using T-Mobile on their iPhone in the US. It’s possible to get a data plan for your iPhone at only $9.99. It’s edge only, but that doesn’t matter because T-Mobile’s 3G network is incompatible with the iPhone’s 3G radio.

Here it is:

  1. Log into your account at Change your device to be a silver (the pink one won’t work!) Motorola RAZR.
  2. As of this writing, there’s a bug in the site that prevents you from seeing the correct data plans for your newly selected device, so log out of the site, then log back in again. Now fFind your way to the page that lists the possible services you can add on to your plan, and you should now be able to select a $9.99/month web plan ($20 gets you unlimited texting as well). Select it.
  3. In your iPhone go to Settings->General->Network->Cellular Data Network and for the APN use Leave the username and password blank.

You might need to wait up to 24 hours for the service to be activated. Just keep restarting your phone periodically and check to see if it starts working.

Categories: iPhone, Tutorials Tags: , ,

How To: Get a Video Screen Capture from Your iPhone

August 15th, 2009 Comments off

I just setup my iPhone so I can control it remotely and ultimately perform video captures of my activity on it. It’s a quick and painless process, and here’s a step by step for those interested:

  1. Jailbreak your iPhone/iPod Touch There are various tutorials around that take you through the jailbreaking process. Just make sure to use the latest version of the jailbreaking tools and install Cydia if you’re prompted.
  2. Launch Cydia and install Veency If this is your first time opening up Cydia, you’ll be prompted about what mode you want the program to run in; select ‘User’. Next click on the Sections tab at the bottom, select the Networking section and scroll down until you see Veency. Select it and press Install.
  3. Download and install a VNC client If you’re on OS X, you can download Chicken of the VNC. On Windows, you can use Tight VNC.
  4. Find your iPhone’s IP address On your phone go to Settings->Wi-Fi then click the blue disclosure button for the network you’re logged into. Take note of your iPhone’s IP address, because we’ll need it later. Mine is
  5. Launch VNC and connect to your iPhone Make sure your iPhone is unlocked and logged into your Wi-Fi network. Launch Chicken of the VNC (or Tight VNC) from your desktop, type in your iPhone’s IP address for the Host, and leave the Display at 0, then hit Connect. You should see a prompt on your iPhone asking you to accept or reject the connection. Veency Prompt
    Go ahead and accept.
  6. Control the iPhone You can control the iPhone with left-mouse clicks and the keyboard. You can simulate a press of the ‘Home’ button with a right-mouse click, and you can simulate the ‘Sleep/Power’ button with a middle-mouse click.
  7. Capture the iPhone screen I like to use Screenflow on my Mac to capture screencasts. I’m not up to date on the best screen capturing software for Windows, but I’m sure there are plenty of options out there.

A couple caveats: The frame rate’s not that great, which produces some artifacts during animations, and any app that uses OpenGL doesn’t work at all.

Categories: iPhone, Tutorials Tags:

t-zones is even easier to setup now

May 11th, 2009 9 comments

After restoring a family member’s iPhone that was acting up, I began setting up t-zones for them, but couldn’t find the t-zones hack in the BigBoss repository. After some experimenting, I soon realized that none of the proxy configuration work is required anymore either. Setting up t-zones on your iPhone is now an easy 3 step process:

  1. Go to Settings->General->Network->Cellular Data Network
  2. Type for the APN (leave the username and password) blank
  3. There’s no step 3!

That’s all there is to it. YouTube even works over t-zones now.

BTW, if you’re a long time T-Mobile customer, you can call in right now and ask about the loyal customer plan. If you’ve been with them long enough, you can have a plan which gives you unlimited minutes for only $50 a month.

Categories: iPhone, Tutorials Tags: ,

Jabeh: Puzzle Game for iPhone and iPod Touch

February 25th, 2009 Comments off

The project that I’ve been working on for the past couple months has finally come to fruition, and is available for purchase on the iTunes App Store.

Jabeh is a puzzle game where you search for 12 hidden stones on a board. Arrows on the board point in the direction of one or more stones, and the column and row numbers show how many stones are in the respective column and row. Using deduction you can figure out where the stones can’t be in order to ultimately find out where all 12 stones are. While you’re playing the game, some light music plays in the background (which you can download for free from the Jabeh website), and when you solve the puzzle you’re rewarded with one of the beautiful pieces of art created exclusively for Jabeh.

You can get Jabeh now for $4.99 or download Jabeh Lite for free if you wanna try before you buy.

Categories: iPhone Tags: , ,

On App Store Download Statistics

January 15th, 2009 Comments off

It seems that nobody wants to release statistics about how their apps are doing on the iTunes App Store, yet a lot of people want to know how well various apps are doing. I’ve seen a couple of examples of income and download numbers, but I’d still like to see more. So, I’m putting my money where my mouth is and publishing the download statistics for my first app, Prayer Book.

For some background about the app, you may want to check out my earlier post. After submitting Prayer Book to Apple on September 24th, they approved it for sale on October 2nd. It was immediately placed on the App Store, but it was never at the top of the recently released apps list, because I had set the release date to be September 24th. It wasn’t until 3 months later that I learned that your order in the App Store has nothing to do with the date Apple approves your app.

Prayer Book Monthly Download Stats

Up until the writing this post, there have been 9,448 downloads of Prayer Book, with an average of 91 downloads a day. Not bad I think. December was a particularly interesting month, so I’ll share some more detailed numbers there.

Prayer Book December Downloads

December was shaping up to be a pretty regular month, and then on the 22nd, there was a spike to 118 downloads, then a drop, and then another spike that lasted from the 25th-29th.

I only have data up to the 13th of January included in the monthly table above, but that’s already further ahead in downloads than the same time in December (941 downloads from December 1-13). Granted, December will probably still be better than January because of the Christmas activity.

Have any links to download numbers for other apps? Please share them in the comments. :-)

APXML: NSXMLDocument ‘substitute’ for iPhone/iPod Touch

January 14th, 2009 3 comments

After spending some time working on Jabeh, my latest creation for iPhone/iPod Touch, I’m taking some time to dump a little learned knowledge into my blog.

In my first app, my XML needs weren’t that great, so putting up with the lack of NSXMLDocument in the iPhone SDK was not a big deal. However, in Jabeh I was changing the XML format so often and using so much of it for my network communication creating delegates for NSXMLParser quickly became a huge time sink. After a little hacking, I came up with APXML to solve my DOM problem. It’s not a perfect implementation of the W3C XML 1.0 standard, but it’s close enough for a lot of usage. One particular shortcoming is its lack of support for namespaces but maybe somebody else can add that support. If you just want to jump in and start using it (LGPL license), you can get the code from github:

Most of my XML manipulation experience has been with various Java libraries (org.w3c.dom interface, JDOM and XOM), and the only one that I enjoyed using was XOM, because of its simplicity and licensing. Almost all of my design decisions were based on how XOM does things.

Let’s say we want to represent the following XML document in memory using APXML:

    <book id="1" author="Michael Pollan">The Omnivore’s Dilemma</book>
    <book id="2" author="Foley, van Dam, Feiner, Hughes">Computer Graphics: Principles and Practices</book>

In code, we do the following:

#import "APXML.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // create the document with it’s root element
    APDocument *doc = [[APDocument alloc] initWithRootElement:[APElement elementWithName:@"books"]];
    APElement *rootElement = [doc rootElement]; // retrieves same element we created the line above
    // create the first book entry (The Omnivore’s Dilemma)
    APElement *book1 = [APElement elementWithName:@"book"];
    [book1 addAttributeNamed:@"id" withValue:@"1"];
    [book1 addAttributeNamed:@"author" withValue:@"Michael Pollan"];
    [book1 appendValue:@"The Omnivore's Dilemma"];
    [rootElement addChild:book1];
    // create the second book entry (Computer Graphics)
    APElement *book2 = [APElement elementWithName:@"book"];
    [book2 addAttributeNamed:@"id" withValue:@"2"];
    [book2 addAttributeNamed:@"author" withValue:@"Foley, van Dam, Feiner, Hughes"];
    [rootElement addChild:book2];


And if we want to convert the document to an NSString*, we use one of the two methods in APDocument:

    // converts the xml to a compact string with no newlines or tabs (good for production)
    NSString *xml = [doc xml];


    // converts the xml to an easy to read string with newlines and tabs (good for debugging)
    NSString *prettyXML = [doc prettyXML];

Often times when I’m working with XML, I like to see what the current element contains, so for added convenience, you can obtain an XML string containing the element you’re working with, its attributes and all its children directly from the APElement by calling one of two methods:

- (NSString*)prettyXML:(int)tabs;
- (NSString*)xml;

Now for the best part of the library, which is the ability to read in XML and represent it in APXML. All you have to execute is one simple line:

    APDocument *doc = [APDocument documentWithXMLString:xmlString];

Hopefully this will be helpful to other developers out there. I may post another article soon if anybody has some questions.

UPDATE Sep 5, 2009: Here’s an example that demonstrates traversing the XML document.

    APElement *rootElement = [doc rootElement];
    NSLog(@"Root Element Name: %@",;
    // get all the child elements (each book)
    NSArray *childElements = [rootElement childElements];
    for (APElement *child in childElements)
        // returns the tag name
        NSLog(@"Child Name: %@",;
        // reads the attribute named ‘author’
        NSLog(@"Author: %@", [child valueForAttributeNamed:@"author"]);
        // returns the text content of the element
        NSLog(@"Title: %@", [child value]);

In the console you’ll see (I’ve removed the NSLog markup):

Root Element Name: books
Child Name: book
Author: Michael Pollan
Title: The Omnivore’s Dilemma
Child Name: book
Author: Foley, van Dam, Feiner, Hughes
Title: Computer Graphics: Principles and Practices

Prayer Book for iPhone and iPod Touch

October 2nd, 2008 13 comments

My first iPhone app has just been posted to the iTunes app store. It’s called Prayer Book and it contains 231 English prayers from the Writings of the Bahá’í Faith. They’re organized by categories and you can bookmark your favorite prayers for easy access as well. I’ll be updating the program over time with new features and prayer translations, and eventually I’d like to have all the Writings of the Bahá’í Faith in there.

It’s available for free on the iTunes store, so go ahead and take it for a spin.

Installing iPhone firmware 2.1

September 14th, 2008 3 comments

Here’s a step by step on how to install the new 2.1 firmware using PwnageTool. I’m assuming that you’ve alread Pwned your phone before when you follow this tutorial. If you haven’t, the steps at the end may be a little different for you.

  1. Update to iTunes 8 and restart
  2. After the reboot, plug in your phone, then open up iTunes. It will ask if you want to update your phone. Click ‘Download only’. If you accidentally clicked cancel, just click on your phone in the iTunes sidebar, then click ‘Update’ to get the latest firmware. Then once the download starts, unplug your iPhone from the USB port.
  3. Once the download finishes, close iTunes
  4. Open up the ‘Activity Monitor’ app from /Applications/Utilities. Find the ‘iTunes Helper’ in the list of running programs and kill it (the red button at the top left).
  5. Set your phone’s auto-lock to never (Settings->General->Auto Lock->Never)
  6. After downloading PwnageTool and copying it to your /Applications folder, launch the program.
  7. Select your device (I’m using the original iPhone) and click the next arrow.
  8. PwnageTool will search for the ipsw firmware file you just downloaded (and it should find it). Select it and click the next arrow.
  9. Now PwnageTool will look for the bootloader v4.6 and 3.9 files. If you don’t have them, you can download them here. After downloading the files, click ‘No’ to searching the web for the bootloader file. At the next dialog, click ‘Yes’ to browse for the location where you downloaded the file.
  10. Now PwnageTool will ask you if you have an iPhone contract that would normally activate through iTunes. If you are using the Apple approved carrier in your country, you can click ‘Yes’, and this will skip the unlocking process on your phone. Just say ‘No’ if you want your phone unlocked.
  11. Now PwnageTool will build an ipsw file for your phone.
  12. After the file is created, close PwnageTool, disconnect and turn off your phone, and open up iTunes.
  13. Now we need to put the phone into recovery mode. While the phone is off, hold down the ‘Home’ button, and at the same time plug your phone into your Mac. Keep holding down the ‘Home’ button until iTunes tells you that your phone is in recovery mode and needs to be restored.
  14. In iTunes, hold down the option key and click ‘Restore.’ Select the new firmware file that PwnageTool just created, and you should be good to go in about 10 minutes.
  15. Enjoy your updated phone!
Categories: iPhone, Tutorials Tags: