It’s after midnight in Brooklyn, NY and I’m fixing the final issues with the beta version of our iPhone application. I don’t doubt it will be an all nighter. Inbetween lines of code, massive amounts of caffeine, and music I check Techmeme in the usual compulsory fashion. As I dodge purple links I make my way to the “More News” section, and I find a “new” article: YC-Backed Glassmap Launches A “Find My Friends” For Facebook Users.
The product I’ve built is in the social/local/mobile space, and I try my best to keep up with all of the innovation in the space so I took the detour. I’m pretty quick to grasp the gist of the app since the author compares it to Find My Friends and Latitude, but then I read about their “killer feature”: relay technology. What? It’s suppose to “minimize the typical battery drains associated with realtime location-sharing apps today. Ok… Then:
"Before, typical location-sharing apps would drain a smartphone’s battery at about a rate of ~5% drain/hour. Glassmap, however, claims to be an order of magnitude (~0.5%/hour) more efficient.”
What? I know that’s bullshit because I’ve researched all the Apple approved ways to run background tasks, and the Apple approved way of getting location in the background causes the ~5% drain. Well, I know that these Glassmap folk must be using an Apple approved background tasks because otherwise they would be rejected from the App Store.
I’m diving deeper down the rabbit hole. RTFM. I made my way down to “Implementing Long-Running Background Tasks”. There are six Apple approved background tasks:
- audio – Play music in background (Pandora)
- location – Get GPS in background (Apple approved way of getting location with ~5% drain)
- voip – VOIP phone calls (Skype)
- newsstand-content – App downloads newsstand data
- external-accessory – App works with hardware that needs to deliver updates on a regular schedule.
- bluetooth-central – App works with Bluetooth
We can use what we know about the Apple App Store rules to deduce Glassmap is not using audio, location (causes 5% drain), newsstand-content, external-accessory, or bluetooth-central.
That leaves an interesting candidate: VOIP. I had some experience modifying VOIP (SIP) datagrams to provide application layer gateway functionality in a two-way transparent proxy, but that’s a topic for another blog post. What’s important about VOIP is that it requires a REGISTER packet to be sent to a central server every so often. I’m almost certain we’ve found the culprit.
I delve deeper into VOIP background execution on iOS. Well isn’t this API a sight for sore eyes? Here’s what’s crucial about that API:
- “timeout” – Minimum acceptable timeout is 10 minutes
- “keepAliveHandler” – Called after “timeout” time has passed, and is permitted to execute for 10 seconds.
What does VOIP offer Glassmap and potentially other app developers? A control channel back to the server. Here’s the scenario:
- Glassmap goes in the background, registers location-based updates, and VOIP handler.
- Glassmap sends the location-based updates to the server, and the server builds a profile about the location (how long have you been there, and are you likely to be leaving soon)
- iOS then triggers the VOIP callback, and Glassmap is permitted to execute for 10 seconds. Plenty of time to send your REGISTER request, receive your OK response which could possibly some extra data that indicates whether to continue to receive location updates. If Glassmap’s servers can determine you’re sleeping or at work, and are not likely move they can signal to turn the radio off. When the VOIP callback is triggered later, they can signal to register for location updates again.
But wait, does Glassmap even have a VOIP feature? Yes!
QED? Maybe. It’s time to finish the beta, but just one last pitstop! I head over to Quora, search “Glassmap”, and I come to How does Glassmap’s battery-saving passive location technology “relay” work? I really need to get back to the code before dawn, so I answer simply: “VOIP is the key here”.
10 minutes later I have a message from Geoffrey Woo (co-founder Glassmap) in my Quora inbox. He’s asking about my mobile experience, and I respond enthusiastically. 20 minutes later Jonathan Zhang (co-founder Glassmap) posts a multi-paragraph answer that is completely vague and close to useless (no offense Jonathan), but he gets voted up by his friends and leaves my answer in the dust (he since deleted his own answer). That’s OK. I have a product to build anyway. By now it’s close to 3 AM, and I have five bugs to fix and two features to implement.
The only pitfall to integrating this approach into your product is it requires you to implement VOIP, and I imagine the Glassmap guys have put in some solid time refining their algorithms.
It’s late, I’m done with DB ops, and it’s time to take heroku off of maintenance mode. Good night!
Best, Brian Donohue
P.S. Thanks Quora Anon User for providing me with the requisite motivation.