An application for Apple Watch to control your Tesla Car

[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.
Tesla_AppleWatch_ELEKSlabs_Cover

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.

Apple Watch Opportunities for Developers

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.

Tesla_AppleWatch_ELEKSlabs_2

Tesla_AppleWatch_ELEKSlabs_3

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:

  • The smart watch has an accelerometer and a gyroscope but when developing, you have no access to them.
  • There is Bluetooth but it can only connect to your iPhone and it’s also not available for developers.
  • Apple watch display is touch sensitive but if you’re developing, only Force Touch, which is used to display the shortcut menu, is available to you.
  • The system of tactile notifications TapTic Engine is, unfortunately, also unavailable.
  • You also don’t have access to the built-in speaker and microphone.
  • It kind of has GPS but only on your iPhone.

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.

Apple Watch for Tesla Car

Tesla_AppleWatch_ELEKSlabs_63

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:

  • Main screen. The status screen that gives an overview of the car including battery, temperature, mileage, etc.
  • Controls menu. A pop-up menu with commands that allows opening/closing the car, switching on the headlights and beeping.
  • Charging screen. The car battery life screen that shows details on the battery and charging.
  • Climate screen. The screen that shows the temperature inside the car and allows changing it in different zones of the car.
  • Location screen. The screen that shows where the car is located.
  • Glance screen. The screen that displays information about the car’s condition for Apple Watch Glance.

Technical Details of the Application

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.

Tesla_AppleWatch_ELEKSlabs_41
Tesla_AppleWatch_ELEKSlabs_5

Problems and Difficulties

During application development, we encountered a number of difficulties, particularly when working on design implementation. Let’s have a closer look at the issues:

  • The first and the most annoying one was running the smart watch app on a simulator. Sometimes, it wouldn’t even start, claiming it is “Waiting to Attach”. The problem is probably in the XCode beta version instability and we didn’t see any dependence on the project settings or anything else.
  • The use of custom fonts in text objects. Trying to use the fonts in the IDE storyboard editor didn’t give us the result we wanted: the font changed alright, but neither size nor color did. Currently, font customization is available only in the code.
    From Apple documentation
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)
  • Digital Crown is quite limited. First of all it is not available in the emulator, so we couldn’t use it in our app. But even worse, third-party apps can only use it for scrolling. Sadly, no custom functionality as for now.
  • Applying design styles to the context menu invoked via Force Touch. Menu buttons and icons on the buttons are gray and don’t allow any design refinements.
    From Apple documentation

Tesla_AppleWatch_ELEKSlabs_7

  • The WKInterfaceSlider element has a translucent gray background which overlaps with the background of the screen, and it can’t be changed or removed. So, to apply our design, we had to create an external likeness of a slider with two WKInterfaceButton buttons and WKInterfaceLabel text.
  • ProgressBar is not available, so we also had to come up with some sort of a likeness.

The Result

You can find all the source code at our Github page and a screencast of the live app running in an emulator below:

width="560" height="315" src="http://www.youtube.com/embed/k6MZCKBNgxc" frameborder="0" allowfullscreen="" style="box-sizing: border-box; margin: 30px 0px; padding: 0px; border-width: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; max-width: 100%;">

Summary

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.

Credits

Oleksandr Malyarenko – co-author, iOS engineer. Follow Oleksandr on FacebookTwitter and Stackoverflow
Vlad Krichenko – designer. Follow Vlad on Facebook and LinkedIn
Oleksandr Bolhovetskyy – iOS engineer.
Roman Kabachenko – idea co-author. Follow Roman on FacebookLinkedInTwitter 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 eleksinfo@eleks.com


内容概要:文章详细介绍了HarmonyOS的目录结构及其重要性,从整体框架到核心目录的具体功能进行了全面剖析。HarmonyOS凭借其分布式架构和跨设备协同能力迅速崛起,成为全球操作系统领域的重要力量。文章首先概述了HarmonyOS的背景和发展现状,强调了目录结构对开发的重要性。接着,具体介绍了根目录文件、AppScope、entry和oh_modules等核心目录的功能和作用。例如,AppScope作为全局资源配置中心,存放应用级的配置文件和公共资源;entry目录是应用的核心入口,负责源代码和界面开发。此外,文章还对比了HarmonyOS与Android、iOS目录结构的异同,突出了HarmonyOS的独特优势。最后,通过旅游应用和电商应用的实际案例,展示了HarmonyOS目录结构在资源管理和代码组织方面的应用效果。; 适合人群:具备一定编程基础,尤其是对移动操作系统开发感兴趣的开发者,包括初学者和有一定经验的研发人员。; 使用场景及目标:①帮助开发者快速理解HarmonyOS的目录结构,提高开发效率;②为跨设备应用开发提供理论和技术支持;③通过实际案例学习资源管理和代码组织的最佳实践。; 其他说明:HarmonyOS的目录结构设计简洁明了,模块职责划分明确,有助于开发者更好地管理和组织代码和资源。随着万物互联时代的到来,HarmonyOS有望在开发便利性和生态建设方面取得更大进展,吸引更多开发者加入其生态系统。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值