iPhone Coding: URL Launcher
Given that Springboard--that is, the iPhone home screen--offers just 4 spaces for custom apps at this time, it surprises me how often I'm asked to create a utility to launch a single URL from a SpringBoard icon. Last night, I gave in and did exactly that. I developed a URL Launcher kit that you can download and customize with your own icon and URL. I guess hope springs eternal that we hackers can crack the big SpringBoard-does-not-scroll issue.
To create your own home screen URL launcher, pop over to the Open URL page and download the latest version of the OpenURL package (currently Version 0.1). Then follow these directions:
- Unpack the OpenURL tar to retrieve the OpenURL.app bundle.
- Inside the OpenURL.app folder, edit the icon.png file to reflect your brand identity. This icon appears on the home SpringBoard screen so make it look pretty and consistent with the overall look of the other icons.
- Edit Info.plist with a unique string. It defaults to com.sadun.ReplaceThis. Change it to something different.
- Edit url.txt and replace the current URL (http://waiterrant.net, a favorite of mine) with the URL you want to launch.
- Rename OpenURL.app to the name you want to appear in SpringBoard, e.g. MyBrand.app.
- Repackage the app and distribute.
That's pretty much all it takes. What OpenURL does is look inside the url.txt file for a URL. It reads it in and launches Safari with it.
To make this happen, I use UIApplication's openURL: method, which you can see in the source code here. When called from within an application, it suspends the current program, transfers control to Safari and instructs Safari to open that URL, preferably in a new page.
Note that you cannot use openURL: to bypass the 8 page limit. When 8 pages are open, Safari launches and displays an alert saying "Could not open a new page because there are too many pages open." Tap OK to dismiss."
The biggest programming challenge for this program involves locating and opening the url.txt string without providing a hard-coded path. Fortunately, the iPhone supports the NSBundle class. With it, you can tell it to look in the top-level folder of the bundle for a file named url with a txt extension:
basepath = [[NSBundle mainBundle] pathForResource:@"url" ofType:@"txt" inDirectory:@"/"];
Once read in, use the whitespace and newline NSCharacterSet to trim any extraneous spaces and new lines from the edges of the URL:
urlstring = [[NSString stringWithContentsOfFile:basepath encoding:1 error: error] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; Finally, create an NSURL from that string and open it:
baseurl = [[NSURL alloc] initFileURLWithPath:urlstring];
[self openURL:baseurl];
Share
Categories
Given that Springboard--that is, the iPhone home screen--offers just 4 spaces for custom apps at this time, it surprises me how often I'm...
Add a Comment
OneMoreAnimal,
I had the same hanging white screen problem that you did. The key was step #6 on http://iphone.natetrue.com/OpenURL/ (this article says the exact same steps, but omits the important part on step #6). The problem is that the file "openurl" does not have execute (+x) permissions when put on the iPhone. I solved this by using the program called "Squid" for the iPhone (available from Installer.app) and navigating to the app folder I created (Gmail.app, in my case) and clicked on the openurl file. Sure enough, the Owner permissions for that file were only Read/Write. I checked "Execute" and then "Apply". Went back to home screen and clicked the icon for the app I created again, and it worked perfectly. I'm on windows Vista and used iBrickr to transfer all the files to my iPhone, btw. It might be a windows/iBrickr issue, whereas mac users don't have the problem. Hope that helps.
Hi Erica, this is just Great, I've installed one icon for each web app with iPhone interface. There is just one thing that is funny. When you open Safari from the icon (openUrl) and the you click in the Home button, there is no animation to get back to the Home Springboard. it looks like some bug with the timing in the animation.
Anyway is a great software, I hope you keep doing this great job.
Regards,
Antonio Carlos Silveira
One of the simplest bits of coding I'm surprised nobody's done yet is a springboard app that sends us straight to All Contacts.
It bugs the hell out of me to always have to tap Phone, then Contacts to get there (especially since going back to the Phone app sends you to wherever you were when you left it - rather than always sending you to favorites, or All.)
Whaddaya think, Erica?
Thanks for all your hard work Erica.
I just followed all the instructions above, and when I launch the app, I get a blank white screen which hangs for 5 seconds and then quits back to the Springboard. Any ideas?
Thanks again Erika for all of your work! I created a page with my favorite searches that I use here:
http://www.applevoicesshow.com/iphone/
This works well as a Springboard icon, but the one thing that's a little rough about it is that it opens a new page each time. Is there any chance of making a version of this that doesn't open a new page each time?
iphone To Do List request:
http://modmyiphone.com/forums/showthread.php?t=3363
Erica,
Any chance of talking you into creating a to do list application similar to the to do list application found on the Palm OS Treos and PDA's? I'd be willing to pay for this, and know many others would as well from the comments over @ modmyiphone. Keep up the great work!!
Jimmie
Or you could use this: http://www.jonsthoughtsoneverything.com/iphone_apper/
hacking seems like too much effort now. hook it up through installer.app!
August 28 2007 at 4:41 PM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Philips Fidelio Primo Speaker Dock for iPhone / iPod for $320 + $6 s&h
- Refurb iHome iH120 Portable Alarm Clock w/ iPod Dock for $18 + free shipping
- miFrame Picture Frame Dock for iPad for $64 + $8 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
- Hannspree Apple-Shaped 28" 1080p LCD HDTV for $270 + free shipping
- Philips wOOx Alarm Clock Radio for Apple iPod / iPhone for $60 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



9 Comments