实质上就是手机的Ajax开发,相比我们熟悉的浏览器开发环境,iphone上做开发还要注意下列几项:
(希望这些经验能顺利跨平台的...好比webkit跑的在nokia上也八九不离个十)
10 must-know guidelines for iphone web app developers
August 31, 2007, 12:21 pm tagged: css html iphone javascript programming
I visited iPhone Tech Talks on 30th of August. Initially I wasn't thrilled about it and didn't have much expectation . However, I found the show to be very informative and fun. I got to seat and chat with many developers who are actively working on lots of cool iPhone apps and services.
In the beginning of the show, they mentioned that we are in bidirectional NDA (Non Disclosure Agreement) contract. I do not see any secretive information from Apple or iPhone's prospective, but Some developers had some interesting ideas which I'm not going to disclose.
There were bast information given in 5 hours lecture - from Developer's scenario to optimizing for iPhone and how iPhone's safari renders web pages. I tried to gather most of the valuable information and organized in category of guidelines. Hope these helps!!
1. Separation of contents:
1. Put all JavaScript on .js file and all styles on separate .css file.
2. Obvious explanation is for better coding and readability, but main advantage is that - this design practice improves loading speed on iPhone, specially on edge network. This is because safari caches all css and js files when they are separate.
2. Use Standards:
1. iPhone supports following standards: HTML 4.01, XHTML 1.0, DOM, CSS 2.1, some CS3, Javascript Ecmascript 3.
2. Does not support WML.
3. My tip, which they didn't mention but I think is good practice, is to use XHTML 1.0 Strict rules instead of HTML 4.01 and XHTML 1.0 Transitional. This ensure most compatibility and speed of browser for rendering.
3. Know the limitations:
1. Resource limitations:
1. 10MB for each text based files (each html, js, css). This is huge, so I don't actually consider as limitation.
2. 8MB for images such as tiff, gif, png
3. 32MB for jpeg images.
4. 2MB of animated gif. If the animated gif is larger, iPhone will simply show the first frame and won't animate.
5. if a page is greater then 10MB, it may load, but would cut resources from any other open window, if available.
2. Javascript limitations:
1. as I mentioned 10MB file size.
2. only 5 second of execute. This is to ensure a script does not make the iPhone non responsive.
1. If the execute time is greater, it will through Exception.
2. So put it on try catch block.
3. Know that script maybe paused. So when window is inactive your script is paused. So javascript timer will not show accurate time when user leaves the safari or goes to different window.
3. Plug-in limitations:
1. No Java
2. No Flash
3. no SVG
4. File System
1. NO File System
2. Upload button will be disabled and grayed out.
4. Know what is supported:
1. Most of javascript functions, events are supported:
1. window.open, target="_new", alert(), confirm(), prompt()
1. even though alert, confirm and prompt are a bad way to send or receive information from users in real desktop browser, iPhone it's totally different case. In fact it is encouraged. The script window looks good and sexy. Feels like real app window.
2. Events:
1. tap triggers onclick, onmousedown, onmouseup and onmousemove
2. two finger triggers mousewheel
3. all other events such as blur, focus, load, unload, reset, submit, change, abort are supported
4. please note that you can not call blur or focus events using javascript. But events will be fired when these events happens.
2. Supported Files within web browser:
1. Excel. Nicely converts to html and put separate sheets as tabs.
2. Word.
3. PDF. Does not support password protected files.
4. Quicktime audio and video:
1. H.264 base 2, 640x480 at 30fps
1. Does NOT support B frames
1. AAC-LC upto 48kHz
2. mov, mp4, m4v, 3gp
3. mpeg-4 part 2
5. Canvas for animation and data driven content
1. Canvas is now Standard
2. Used to create all Mac OS Widget
3. now supported by Opera, Firefox
4. iPhone uses complete implementation
5. iPhone's stock uses Canvas to animate and show data
3. Built-in Fonts
1. Ariel, Courier, Georgia, Trebuchet, Zapfino,Helvetica, Times, Verdana
5. Scaling/Zooming and META tag:
1. iPhone will scale a web page to 980x1091 first, then scale back to 320x480. They use this technique for all web sites.
2. iPhone looks for following meta tags for overriding default scaling:
1. <meta name="viewport" content="width=320">
1. this will not scale at all and just render the page to 320 width
2. <meta name="viewport" content="initial-scale=1">
1. initial-scale = 1 means 100%, 2 means 200% and so on.
3. other values for contents
1. user-scalable=yes/no
1. if set to no, user can't pinch or zoom
2. minimum-scale or maximum-scale
3. Control zooming on every element of the HTML page
1. use -webkit-text-size-adjust property to control zooming by double tapping to all html elements including div, table, body.
1. -webki-text-size-adjust has following values:
1. none: disable zooming
2. auto: let Safari handle it
3. %: set to a percentage
6. Integrate with iPhone's app
1. integrate with Google Map Application
1. simply like using anchor with <a href="/map?q=pizza+10018">show me pizza!</a>
2. q parameter is for terms
2. integrate with Phone App
1. <a href="tel:+1(800)222-2222">call us</a>
3. integrate with Mail App
1. <a href="mailto:
[email protected]?subject=hello&message=this is a message">email me</a>
7. Understand iPhone's User Agent
1. iPhone User Agents has following terms
1. iPhone;U;CPU like Mac OS X;en
2. AppleWebKit/420 - gives WebKit version
3. Version/3.0 - 3 for Safari 3 family
4. Mobile/xxxx - iPhone Safari build number
5. Safari
8. Understand iPhone Safari's preference:
1. This is important because developer needs to know that users can disable and enable some features from the iPhone's Setting.
1. javascript can be turned off (on by default)
2. pop-up block can be turned off
3. cookies policy can be changed just like desktop Safari
9. MISC. Tips:
1. create rounded rectangle:
1. user -webkit-border-radius css property to create nice rounded rectangle.
2. create button or header
1. user -webkit-border-image to create nice headers and buttons
3. user javascript frameworks
1. iUi (praised by the staffs)
2. YUI (Yahoo library)
3. dojo
4. prototype
5. JQuery
4. use CS3 media query to detect iPhone when including css files
1. iPhone returns "screen" and width value
5. turn on server-side compression
1. this alone can save up-to 50% of download time.
10. DEBUGGING
1. Turn on developer's menu for safari,learn how.
2. Download nightly build Webkit which includes excellent and extended "Inspect Element" tool. http://webkit.org/
3. User Drosera (comes with nightly build webkit for only for Mac) for debugging Javascript.
转帖 :
http://alaminahmed.com/?id=10_mustknow_guidelines_for_iphone_web_app_developers