In the latest days I worked on websites optimizations for iPhone and iPad. I found some tips that can be useful and I want to share it.
PHP detecting
You can detect if the device viewing your site is an iPad, iPhone or iPod using this code:
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPad')){
//Do something
}
else if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')){
//Do something
}
else if(strstr($_SERVER['HTTP_USER_AGENT'],'iPod')){
//Do something
}
iPhone icon
This icon will be used when the user add your website to their home screen. Use the following code to specify a custom icon, the icon size must be at least 57×57 pixel.
<link rel="apple-touch-icon" href="/iphone.png" />
Viewport settings
A typical mobile-optimized site has something like the following:
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
The property you can set are:
- “width”: The width property controls the size of the viewport. It can be set to a specific number of pixels like width=600 or to the special value device-width value which is the width of the screen in CSS pixels at a scale of 100%.
- “minimum-scale”, “maximum-scale”, “initial-scale”: The initial-scale property controls the zoom level when the page is first loaded. The maximum-scale, minimum-scale, and user-scalable properties control how users are allowed to zoom (pinch) the page in or out.
About viewport there’s an interesting article from quirksmode.org here.
Media query
The css code inserted in this query is read only from iPhone:
@media screen and (max-device-width: 480px){
/* CSS */
}
Background issue
Mobile safari scales your whole site down to its viewport size, including the background image.
To achieve the correct effect, use the “-webkit-background-size” CSS property to declare your background size:
-webkit-background-size: 2650px 1440px;
