notbrainsurgery (notbrainsurgery) wrote,
notbrainsurgery
notbrainsurgery

Push Email on iPhone with ActiveSync

If you want to get “push” email on your iPhone you have now just two options. You can either go with Apple MobileMe service or with Microsoft Exchange account. I will discuss MobileMe push implementation in a later post. Let us today review how push is implemented with Exchange mail accounts on iPhone.

The fundamental problem with “push” email is a battery life. In order to get notified about new email one needs to keep a connection to server open, so server can notify your phone about new messages as they arrive. However in mobile environment as you move, your IP change. Also to work reliably on various WiFi hotspots one can rely only one one protocol to be working: HTTP. The latter is not a problem, since ActiveSync protocol (used by MS Exchange) is using HTTP transport. The issue with HTTP is that is not designed to send data from a server to a client. Client always need to send a request and only then, the server can respond. To get notified about new message within, say, 10 seconds, client needs to poll server doing HTTP request every 10 seconds. This would eat your battery pretty fast.

The ActiveSync solution to this problem is so-called “long pull”. The client does HTTP request to the server (PING protocol command). If there is no new data, instead of responding to the server’s request right away, the client hangs on there as long as possible, delaying the answer. If new data arrives while client is waiting for PING response, the server sends it back right away. If not, after some time the PING is completed, and new one is immediately sent by the client. For example is a server can delay his response to PING connection for up to 900 seconds, in the absence of new mail HTTP requests will be sent once in 900 seconds. At the same time, if new message arrives, the client will be notified immediately. The key point, is that on packet switched radio network like GPRS, a connection which is waiting for response without sending any data does not use additional battery power compared to a regular device standby power consumption. So with this clever trick not only almost instant new message notification could be provided, but the battery consumption is significantly better compared to just polling.

iPhone Push Settings Now, let us look closer at iPhone. iPhone have 2 radios: WiFi and 3G (which also can do EDGE or good old GPRS). The phone could be in active mode (the screen is on) and asleep (the screen is off). Interestingly, even if a known WiFi network is present and available, iPhone will still be using 3G to poll server for new mail. This is done presumably because 3G radio by design have lower battery consumption compared to WiFi. Once a new messages are detected using PING command, iPhone will beep and fetch them using SYNC command. Here it behaves differently depending on the mode it is on: if it is ON and WiFi connection is available, it will use this connection to fetch new messages. Presumably this is done because messages could be quite big and WiFi generally speaking is faster than 3G. However, if the phone is asleep, even if WiFi connectivity is available, it will use 3G to fetch new messages. Here, preserving a battery power have a priority over the speed of download. To sum it up: PING is always done over 3G, while SYNC may use WiFi if the phone is active and known WiFi network is available.

What about iPhone little brother, iPod Touch? It also has a Mail client and WiFi radio (but not 3G). So it has to use energy inefficient WiFi connection for both PING and SYNC commands. To avoid draining the battery, it just stops PINGing your Exchange server in approximately 12 minutes after it goes to sleep. At this point, depending on user settings for regular (non-push) fetching, it will either will switch to polling ever 15 or 30 minutes (using SYNC command) or will just stop checking for email is "Manually" is selected as polling schedule. This is little misleading, since settings screen for mail retrieval schedule clearly states that schedule is used only if Push is disable or not supported. 

I have not tested how iPhone behaves if 3G not available but WiFi is. I just could not find such spot neither at my home nor at my office. I suspect that it will behave exactly like iPod touch.

P.S. Described above iPhone and iPod touch behaviour applies to firmware version 2.2. It might work differently with other versions.









Digg!
Tags: 3g, activesync, apple, email, exchange, iphone, ipod, mail, mobile, push, wifi
Subscribe

  • Amazon Instnat Video, Comcast and Google DNS

    As Amazon Prime Customer I have access to Prime Instant Video. I have a PS3 with Amazon Instant Video application connected to my TV which I tried…

  • Google Apps

    My company has recently switched to Google Apps (paid edition). It is not cheap: $50 per user annually, but we decided it is worth it, comparing to…

  • unscientific google chrome performance test

    Google is advertising Chrome as a very fast alternative to other browsers. I am also trying to use Google Wave and I have noticed that on long…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 18 comments

  • Amazon Instnat Video, Comcast and Google DNS

    As Amazon Prime Customer I have access to Prime Instant Video. I have a PS3 with Amazon Instant Video application connected to my TV which I tried…

  • Google Apps

    My company has recently switched to Google Apps (paid edition). It is not cheap: $50 per user annually, but we decided it is worth it, comparing to…

  • unscientific google chrome performance test

    Google is advertising Chrome as a very fast alternative to other browsers. I am also trying to use Google Wave and I have noticed that on long…