iPhone

Detect Iphone

Thursday, March 11th, 2010


I got inspired and wanted to finish up the iphone version of my website. To do this, first you need to detect the iphone and then redirect the user to another webpage. Here is the script to do that:

1
2
3
4
5
<script type="text/javascript">// <![CDATA[
	if ((navigator.userAgent.indexOf('/iPhone/i') != -1) || (navigator.userAgent.indexOf('/iPod/i') != -1)) {
		document.location = "http://www.scottrockers.com/iphone.html";
	}
// ]]></script>

Add this Javascript inside your <head> tags. and change the document.location to the page you want the user to get redirected to. The reason I have a iPhone version of my website is because my home page is made in Flash and as you know the iPhone can’t display Flash yet. So I created a basic html page that has a div in the body of it that is sized to 300 width by 350 height. And if you put this line of script in the <head> section it will tell Safari that the viewport should be the same size as the iPhone screen. Setting this line of code forces the content to always fit the window.

1
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">

Now, if someone wants to bookmark your website, they can hit the + sign and then click “Add to Home Screen” and you want to specify what icon to use for the iPhone, then create a 57px by 57px .png formatted image, put it up on your server and put this line of code in to your <head> section as well.

1
<link rel="apple-touch-icon" href="http://www.scottrockers.com/library/images/sriphonelogo.png"/>


Just make sure the href tag is the correct destination to your image. What is cool is that you don’t have to add the corners or shine effect on the webclip because the iPhone will do that for you.

If you want to see all the actual html code, you can just go to scottrockers.com iPhone Version and click view source.

Cya

How to Detect iPhone and Redirect to iPhone Version Website

Wednesday, December 9th, 2009

I came across a useful snippet of code that I wanted to pass on and post about. It detects whether the person viewing your website is on a iPhone or computer. If they are on a iPhone, you can redirect them to a iPhone version website or just to another page, its up to you. If they are on the computer it doesn’t redirect them and they go on as normal. Its just some simple javascript, and if you want to use it just change the “document.location” value to the url you want them redirected.

1
2
3
4
5
<script type="text/javascript">// <![CDATA[
	if ((navigator.userAgent.indexOf('/iPhone/i') != -1) || (navigator.userAgent.indexOf('/iPod/i') != -1)) {
		document.location = "http://www.scottrockers.com/iphone.html";
	}
// ]]></script>

Cya

31 Days of iPhone Apps

Thursday, January 15th, 2009

iPhone App Store

I just found a new site today that wrote 31 iPhone applications in 31 days, its called AppsAmuck.  And I think its a good place to start to create my own iPhone App.  I have been thinking about doing this for a little while now because my wife got an iPhone for Christmas.  I want to see what I can do with it, because I really love the interface and motion controls of the iPhone.

There have been a few hiccups I have come across already while researching this. First off, the iPhone Development Center says that the SDK to develop the apps in is only available for the Mac OS X Leopard.  This is quite a big hurdle for me since I don’t have a Mac, but my brother (Adam) has already started trying to figure out what to do about this. So Adam and Mark, a co-worker of ours, have gotten Leopard to work on his a virtual machine running on Windows, now we just have to replicate his process.  The second hiccup is that to publish these apps to the actual app Store on the iPhone, you have to pay a licence fee of $99.  I guess this can come later if actually do come up with some cool apps. So it may take a little longer than I thought it would to get started but it will happen.

I will post an update once I know more.

Cya