Apple Watch application development experience: the pitfalls I encounter, watch Application Development

Source: Internet
Author: User

Apple Watch application development experience: the pitfalls I encounter, watch Application Development

The author of this article, Zhang Zhongliang, is a developer of the Apple Watch application. He spent a week using pure Objective-C language to complete the development of the Apple Watch tick list application. Here, he elaborated on his personal understanding of Apple Watch from the perspective of development, as well as his experiences in the Apple Watch application development process, which is suitable for those who have some knowledge about iOS development.

First, you must master the WatchKit Framework to develop an Apple Watch application. This is a new Framework developed by Apple for Apple Watch. All classes in this framework start with "WK", including View Controller WKInterfaceController and WKUserNotificationInterfaceController, and other UI element classes such as WKInterfaceGroup, WKInterfaceTable, WKInterfaceLabel, and WKInterfaceButton. The specific usage will not be described here. If you want to systematically learn WatchKit, you can read Chun Tips's "go into WatchKit Framework".

However, I personally strongly recommend that you read the original official document carefully if you have time to help you better understand the API for development, it can also reduce the chance of generating bugs to a certain extent.


The development of the Apple Watch version of the tick list is still relatively smooth. With the blood and tears from designers and product managers, I have been working for almost a week. At present, the application has been launched. Here, the specific development process is not detailed, it is nothing more than the UI building and logic processing. I want to help you with some notes during development.

  • Technically speaking, the WatchKit App is similar to the new App Extension (App Extension) launched on iOS 8, such as Today Extension (Today's Extension) and Share Extension (Share Extension ). As long as you have some experience in iOS development, it is relatively easy to build the UI.The focus is on how to synchronize data on the iPhone and Apple Watch. The question is, how?

See:

1 -(NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier;

After iOS 8, NSFileManager has such a method. If your application already supports the App Group (which will be introduced later), you must also have groupIdentifier, call this method to return the URL of a local file directory. Simply put, it is a shared folder. Any application or extension, as long as it supports the App group and has the same Group ID, has read and write permissions on it, so that data synchronization is not a problem. If you want to learn this in detail, you can read iOS 8 Extensions. I can only say that it is hard to understand it! However, we recommend that you read the official Apple documentation. The original version is the best.


Although data can be synchronized, how can I know on Apple Watch that a new task has just been created on the iPhone? You don't need to think about it. The cost of building a wheel is high and prone to problems. MMWormhole is recommended here. It is a mature and stable third-party open-source library used for communication within the App Group, which is very convenient and easy to use. I will not talk about the principle. If you need it, you can download it and study it.

  • When building the UI, you will find that Apple Watch does not support AutoLayout (if you are still working on the manual layout, do not struggle with your child and study AutoLayout well), what should you do? Can I only deploy Code only?

Of course Apple won't be so earthy. WatchKit has a class called WKInterfaceGroup. At first glance, it looks like UIView, but this product is actually used for layout. Pull a WKInterfaceGroup from the Storyboard, and there is a Layout attribute in the Attributes Inspector. By setting it to Horizontal or Vertical, you can arrange all the sub-views in the group horizontally or vertically. With the knowledge of AutoLayout, we can easily meet any non-human requirements of designers.

  • WKInterfaceTable in WatchKit is different from UITableView. Without dataSource and delegate, data can only be automatically filled and displayed. For each cell of different types, a rowController (inherited from NSObject) must be constructed for it. The rowController is responsible for filling the content to be presented in this type of row.

The method is as follows:

1 -(id)rowControllerAtIndex:(NSInteger)index;

Call this method to get the rowController of the specified row, and then call the custom method of the rowController for rendering. For example:

1 - (void)configureRowWithDataModel:(id)dataModel;

In addition, to insert or delete a row, you must call the following before the preceding operation:

12 -(void)insertRowsAtIndexes:(NSIndexSet *)rows withRowType:(NSString *)rowType;-(void)deleteRowsAtIndexes:(NSIndexSet *)rows;

Everything goes well here, but don't be so happy. Apple has dug a big hole here. Please do not step in!

To refresh the UITableView in iOS development, you only need to update the data source and then call the reloadData method. As mentioned earlier, WKInterfaceTable does not actively refresh data. You can only clear all data by calling the [table setRowTypes: nil] method, and then refill it with the new data source. This is the only way to do it. It's even more brutal.

If you are now in View Controller A and then pushed to View Controller B, it is useless to refresh WKInterfaceTable in View Controller A in View Controller B. But it is not completely useless. After multiple tests, I found that the data source was indeed updated, but the content on the interface was not refreshed. That is to say, the data source and interface are not consistent. I have searched the official documents and major technical forums and have not found any solutions. It seems that this is an Apple bug in the developer forum.


The temporary solution is to record a tag bit when you need to refresh, And then refresh the tag Based on the tag bit latency during willActivate. One obvious side effect is that the refresh will be broken. I believe that later versions of Apple will fix this problem.

Let's talk about the following:

I personally think that whether it is optimistic or pessimistic about Apple Watch, it is only for the new platform of smart Watch, not the product itself. I believe that no picky person can pick any thorn from this art. Apple had to delay the delivery time at the beginning of the pre-sale, which is a good illustration of its charm.

Maybe you will say that this is because people are generally curious about new things and are actively paying attention to them, not just because they are excellent, but we have to admit that, apple Watch is impacting the smart Watch platform and even the entire ecosystem. Health monitoring, remote control, and mobile payment. If all the tasks with low operating costs, short cycle, and high timeliness can be entrusted to them, will our life be simpler?


Take the ticking list as an example. At the beginning, developing the Apple Watch version came with an enhanced reminder. When I put my cell phone in my pocket or on one side, there was just a task, and it was very likely that I did not receive it (I often encountered this situation). It was too late to check my cell phone. Unlike mobile phones, there is almost no human-machine separation between Apple Watch and Watch, and task reminders are not easy to miss.

Therefore, we pay more attention to its advantages in Mobile scenarios: Free Hands, anytime, anywhere. Mobile phones are also very convenient, but no one is always holding a mobile phone. Once the mobile phone is not in the hands, many things cannot be handled. Although the Apple Watch screen is relatively small, it is much easier to operate in some scenarios.

In future planning, we will also focus on the advantages of Apple Watch and some features of our products. Currently, the Apple Watch application we developed is like a lite version of the mobile app, which only enhances the auxiliary functions. In the future, you may try something different from the mobile app. Apple Watch has some powerful functions, such as monitoring users' heart rate and other data, we may make some real-time smart reminders based on the data. Of course, they are just some ideas that need to be tested.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.