[https://github.com/eleks/rnd-apple-watch-tesla]
[http://elekslabs.com/2015/01/apple-watch-tesla-car-how-far-can-we-drive-them.html]
DISCLAIMER: Tesla Motors Inc. was not involved and did not endorse neither author, nor ELEKS Ltd. in experiments and application described in this article. TESLA logo and brand name were removed from this article under request of Tesla Motors Inc.
Developers have always had an irrepressible desire to learn something new, interesting and useful, especially if it’s connected with IT. At ELEKS, we have the same, if not greater, craving for innovations. That is why we couldn’t let the emergence of the smart watch from Apple simply pass by. Said and done.
A couple of days, gallons of coffee and hours of restless peering into monitors later, we developed our first Apple Watch app that allows controlling the Tesla Model S electric car via the Internet using web-service API. The app perfectly lines up with the concept of smart watches, lets the user access critical information about the car and allows managing it quickly without wasting time on taking out and unlocking the phone.
If you’re familiar with WatchKit – an SDK for Apple Watch applications development, here’s a shortcut straight to the Tesla Watch app chapter.
If not, you’re in for a ride through the technical capabilities of WatchKit. Apple has kindly provided the beta version of the SDK for the Developer Program participants. And here, unfortunately, not everything is as smooth as in Tim Cook’s presentations.
Briefly speaking, Apple Watch is simply an additional monitor to your iPhone and it can’t do anything by itself. Here is what Apple representatives say about this:
“Apple Watch applications complement your main iOS apps and do not replace them. If you measure the time a user spends in the app in minutes, then interaction with the Apple Watch application can be measured in seconds”
It is the iPhone app that contains all the code in the form of a so-called Watch Extension (another type of extensions in addition to Today Extension, Share Extension, etc., brought to us by iOS8), and on the Apple Watch side we have only application resources and UI display (as Storyboard). Here are the diagrams, kindly provided by Apple, that explain its work and communication between the smartphone and the smart watch.
As we can see now, Apple Watch without an iPhone is actually nothing more than a useless toy. And although Apple mentioned WatchKit Apps – full-featured applications that, in theory, should work without an iPhone, this kind of applications aren’t available yet and no one knows when they will be. On the other hand, this significant drawback is, surprisingly, a big plus. Since the smart watch application is carried out on the iPhone, all the functionality and data from the iPhone is available for the developer (though Apple has already warned us about possible restrictions on energy-intensive operations). WatchKit is kind of a “bridge” linking code on an iPhone with Apple Watch interface.
All Apple Watch applications work in three options. The first one is a complete app you can use from the smart watch screen. The second, Glances, only shows cards with information necessary for the user. The third one is active notification with two scenarios: 1) if you raise your hand to look at the notification and don’t put it down for a couple of seconds, the smart watch will show you more detailed information; 2) you can quickly react to notifications by performing certain actions.
If you look at the opportunities available for smart watch application development, you’ll also see a quite pessimistic picture. Apple does not indulge developers with an abundance of functionality and tools. However, we can hope that the available functions are limited because this is only the first beta version and it will get much better towards the release.
And now for the bad news. I mean the functions that are not available to the developers:
So, from the development perspective, Apple Watch is currently a quite limited device with a weak potential for programmers. No, hold on. Perhaps this statement isn’t entirely correct, since the smart watch isn’t selling yet and we can only make our assumptions based on the SDK that is in its first Beta stage. As a result, we get rather mixed feelings from the smart watch. On the one hand – everything is beautiful, new and interesting, and on the other – the stripped-down functionality makes it impossible to develop beautifully designed really functional apps right now.
But ELEKS developers don’t quit. We were determined on implementing all the available Tesla car control functionality, adapting the UX to the context of Apple Watch. So, after a little brainstorming, we decided on 6 screens:
Just like the iPhone app version, Watch Extension for the smart watch connects with Tesla web-service API via a separate service operations module. This module is implemented as a separate Cocoa Touch Framework (another advice from Apple for developers who create apps containing Extension).
Also, we implemented a mechanism of data exchange between an iPhone and Apple Watch using the “shared app group”:
“An app group is an area in the local file system that both the extension and app can access. Because the two processes run in separate sandbox environments, they normally do not share files or communicate directly with one another. An app group makes sharing data possible. You might use the space to store shared data files or to transfer messages between the two processes.”
From the documentation for developers.
Here is a sample of code that allows loading and saving data in NSUserDefaults:
1 |
+ ( void )saveSummaryModel:(SummaryModel *)summaryModel { |
2 |
NSData *archivedData = [ NSKeyedArchiver archivedDataWithRootObject:summaryModel]; |
3 |
NSUserDefaults *defaults = [LocalStorageHelper getSharedDefaults]; |
4 |
[defaults setObject:archivedData forKey:SummaryModelKey]; |
5 |
[defaults synchronize]; |
6 |
} |
7 |
+ (SummaryModel *)loadSummaryModel { |
8 |
NSUserDefaults *defaults = [LocalStorageHelper getSharedDefaults]; |
9 |
NSData *archivedData = [defaults dataForKey:SummaryModelKey]; |
10 |
SummaryModel *summaryModel = [ NSKeyedUnarchiver unarchiveObjectWithData:archivedData]; |
11 |
return summaryModel; |
12 |
} |
13 |
+ ( NSUserDefaults *)getSharedDefaults { |
14 |
NSUserDefaults *sharedDefaults = [[ NSUserDefaults alloc] initWithSuiteName: @"group.eleks.TeslaModelS" ]; |
15 |
return sharedDefaults; |
16 |
} |
We also created a beautiful and user-friendly design that meets all Apple’s requirements.
During application development, we encountered a number of difficulties, particularly when working on design implementation. Let’s have a closer look at the issues:
1 |
// Configure an attributed string with custom font information. |
2 |
let menloFont = UIFont(name: "Menlo" , size: 12.0)! |
3 |
var fontAttrs = [ NSFontAttributeName : menloFont] |
4 |
var attrString = NSAttributedString (string: "My Text" , attributes: fontAttrs) |
5 |
// Set the text on the label object |
6 |
self .label.setAttributedText(attrString) |
You can find all the source code at our Github page and a screencast of the live app running in an emulator below:
Although the opportunities seem pretty huge with Apple Watch, unfortunately, the current capabilities of the emulator-only development don’t match the expectations set after the keynote. We can now confidently say that creating anything really necessary and fully functional for Apple Watch with the current SDK version is very, very difficult, and many of the things promised at launch that were perfect for some business ideas are not at all available yet. The only thing left for the developers is to wait for spring 2015 when a new version of WatchKit will be released and Apple Watch will finally start selling.
Oleksandr Malyarenko – co-author, iOS engineer. Follow Oleksandr on Facebook, Twitter and Stackoverflow
Vlad Krichenko – designer. Follow Vlad on Facebook and LinkedIn
Oleksandr Bolhovetskyy – iOS engineer.
Roman Kabachenko – idea co-author. Follow Roman on Facebook, LinkedIn, Twitter and StackOverflow
Viktor Maleichyk – idea co-author. Follow Viktor on Facebook
If you’re interested in application development for Apple Watch, Android Wear or Pebble, feel free to contact us at [email protected]