Pushing tweets to your iPhone with Apple Push notifications

Ars shows you how to create a Push-based Twitter update notification system …

Last night, I worked out the new Apple Push remote notifications for iPhone 3.0. I cobbled together a system that allows you to subscribe to an RSS feed from search.twitter.com and push new updates to your phone as they appear. Now, in what's going to be a more remarkable task, I'm going to tell you how to do this while staying within the limitations of the NDA. Here are the steps.

Create your provisioning

Push provisioning requires a slightly different approach than provisioning for normal iPhone applications. Apple has posted complete details on doing this at its developer program site. Go there, log in, and head over to the application identifier tab. There you'll find what you need to get started and Apple will walk you through the process of obtaining your certificate. After that, create a mobile provision file as instructed. You can't use your normal wildcard development provision to build your client.

Build a client

Creating the client application requires just a few methods. The client methods are discussed in Apple's documentation. Make sure you implement all the necessary delegate callbacks and that you follow the directions on the developer forums to retrieve the required identifier. Getting the identifier is critical for making the process work. Your client needs do nothing more than let the system know that it wants to participate and produce that identifier. Make sure to sign your client with the non-wildcard provision.

Install the Perl client

Again on the developer forum, look for the brilliant and easy-to-use Perl script that has been posted. Make sure to follow the set-up instructions exactly for downloading the required module from CPAN. Substitute your identifier in where you are instructed to do so. The script tells you how to convert your .cer certificate into p12 and then pem. Do this and place the files into a new subfolder named certs.

After this, you should be able to test out your connection, which has worked flawlessly for pretty much everyone I know who has tried this. The utility, which I called push.pl, takes one argument, a JSON data string which is sent to the push server. Again, see the Apple docs for how to build that data string.

Create the Twitter utility

Once you have confirmed that you have Push working, download a copy of my push-tweet source. You'll need to make a bunch of edits to this source. Change TWEET_FILE to point to your home folder, set URL_STRING to the actual twitter search you want to use, and finally you must add your own JSON push request. It's not hard to create, especially if you just need a single string (the tweet/user) and an Okay button. Since Apple's docs are under NDA, I can't show you exactly how to construct this, but it isn't hard.

The push-tweet utility, when compiled, takes one argument, the number of seconds to wait between each scrape attempt. Push-tweet downloads the latest RSS page, extracts the first tweet found and compares it to the most recently pushed tweet. If they differ, it pushes that new tweet and saves the new tweet for comparison.

As I learned last night, you probably want to turn off the script (and possibly push altogether) at night. Push notifications can be very bright indeed.