views:

244

answers:

3

hello to all, i was asked by a client to set up a landing page for iphone users. the page already exists - very simple, just a few images and text. i need to: - make sure its iphone compatible (any special tags or definitions?) - make sure google mobile search indexes it as a mobile page - in the home page (different page, for all users) re-direct iphone users to the special landing page if i detect the are browsing via iphone.

i realize i'm asking a lot.. any help,such as links to tutorials you found useful etc. would be highly appreciated.

Have a nice day :-)

+1  A: 

I wrote a blog post introduction about developing for the iPhone. The top section gives a small introduction to the web based approach and you may find it useful.

Apples iPhone Dev Centre for Web Apps will give you far more detail about what you need to know.

Richard
A: 

Hey there,

The best thing to do is to setup a before_filter in your application controller that checks for the iPhone Mime-Type. Go to config/initializers/mime_types.rb and add this line

Mime::Type.register_alias "text/html", :iphone

And here is the method that gets called in a before filter in my ApplicationController.

def mobile_user_agent?
  agent = request.env['HTTP_USER_AGENT']
  return false if !agent
  return :iphone if agent[/(Mobile\/.+Safari)/]
  return :iemobile if agent[/IEMobile/]
  return :blackberry_4_3 if agent[/BlackBerry.*4.3.0/]
  return :blackberry_4_7 if agent[/BlackBerry.*4.7.0/]
  return :android if agent[/Android/]
  return false
end

Then in your controllers you can do the following in your controllers.

def index
  @posts = Post.find(:all)
  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @posts }
    format.iphone # render index.html.iphone
  end
end

This lets you render iPhone specific views. You can do the same thing for all kinds of Mobile phones, Android, Blackberry, Windows Mobile etc...

I can't take all of the credit for this :) Mike Clark and the Pragmatic Programmers featured a solution like this in Advanced Rails Recipes.

My only other advice would be that if you are doing a lot of different iPhone stuff in your app, then make a separate controller called IPhoneViewController or something that handles all of the iPhone stuff.

Good luck! If you need anything else let me know,

Kent

ewakened
Is this a Ruby on Rails solution? @samoyed doesn't say what server side language they're using.
Richard
Hahah yeah that's so true :S I just assumed... you can do a similar thing in Ramaze, Sinatra, Camping etc... but if it's straight ruby, then yeah you will need to build a lot.
ewakened
A: 

For submitting the site to Google for the mobile search indexing: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=40348

The easiest way to find out if your page or site is compatible with the iPhone is to try it. If you do not have an iPhone, the iPod touch has the same web browser.

Sarah Happy