Introduction to Apple Watch Development (i) Configuring Xcode project

Source: Internet
Author: User

The WatchKit app requires an existing iOS app. In the iOS app project, add a new WatchKit app target that contains the resources needed in the WatchKit app and WatchKit extension. They will be posted to AppStore with the iOS app.

WatchKit app Target provides all the resources for the initial creation of WatchKit App,glances, as well as custom notification interfaces. The iOS simulator can be used to test all the interfaces and behaviors.

Note: WatchKit development requires iOS 8.2 or an updated SDK.

Add WatchKit app to iOS project

You must have an iOS app to create the WatchKit app. The WatchKit app is implemented in different target of the Xcode project, and is bundled with the iOS app when packaged.

1. In Xcode, open the iOS app.

2. Choose File->new->target, but change to the Apple Watch page.

3. Select the WatchKit App and click Next.

4. If you plan to implement glance live custom notification interface, select the appropriate check box.

For the notification interface, it is recommended that the include Notification scene check box be selected, even if it is not currently scheduled to be implemented. Select the check box to add a debug notification interface file to the project. If you do not choose, you will need to manually create those files later.

5. Click Finish

Xcode configures the target of the WatchKit app and WatchKit extension and adds the required files to the project. The bundle ID is automatically configured based on the bundle ID of the iOS app. The base ID (prefix) of the three packages must match. If you change the bundle ID of the iOS app, you have to modify the other bundle IDs as appropriate.

APP Target Structure

Adding the WatchKit App target to the project also adds two new executables and updates the project's build dependencies. Compiling an iOS app compiles three executables (iOS app, WatchKit extension, and WatchKit app) and packs them together. Xcode also adds a build scheme to compile only the debug WatchKit app.

Shows the iOS app and WatchKit. The WatchKit app is packaged in WatchKit extension and WatchKit extension is packaged in Iosapp. When a user installs an iOS app on an iphone, if there is a matching Apple Watch, the user is recommended to install the Watch Kit app. iOS automatically handles the installation process.

Compile, run, debug

When you create the WatchKit app, Xcode automatically creates a build scheme to run and debug the WatchKit app. Use this scheme to run the app on an iOS emulator or device.

For apps that contain glance or a custom notification interface, you need to configure additional scheme to test these interfaces.

Configuring a custom scheme for glances and notifications

1. Select the existing WatchKit app scheme.

2. In the Scheme menu, select Edit Scheme.

3. Copy the existing WatchKit app scheme and take a proper name.

For example, called "Glance-my WatchKit app" to represent the scheme of running and debugging Glance

4. When editing scheme, select Run on the left

5. In the Info section, select the appropriate execution target for the new scheme.

6. Save to close the scheme editor.

When creating a scheme for the notification interface, specify a JSON file when testing.

Specifying test notification data

When you debug a custom notification interface in the emulator, you can specify a JSON data at test time. Use the Scheme editor to specify which data file to use. The data file is terminated with a. APNs suffix.

Note: If the Create WatchKit app is selected in the Include Notification Scene. Xcode provides a test Pushnotificaitonpayload.apns file by default. (Files in WatchKit extension's Support folder) can also be created manually later.

The Pushnotificationpayload.apns file contains most of the fields that simulate remote notifications, or you can add fields yourself. Shows the default JSON file

The JSON data is packaged into dictionary and then passed to the code at run time. Because the iOS emulator cannot register an action event for the iOS app, you can also use a JSON file to specify the action buttons that appear on the interface. The WatchKit simulator can contain a set of actions, each representing an action button to be added to the interface. Each data contains the following keywords:

    • Title-the caption of the action button. This keyword is a must.
    • identifier-This string is the Application:handleActionWithIdentifier:forLocalNotification:completoionHandler that is passed to the interface controller: Or Application:handleActionWithIdentifier:forRemoteNotification:completionHandler: Method. This keyword is required.
    • destructive-its value is 1 or 0, and 1 indicates that the button is displayed as a button to perform the destroy operation. 0 indicates that the button is displayed in a normal manner. This field is optional.

To test the notification interface with JSON data, you need to select the corresponding data file in the scheme. When you select the type of scheme as a notification, Xcode displays a menu that selects the JSON data. You can create different scheme for different notification data, or you can edit shcme before testing.

Introduction to Apple Watch Development (i) Configuring Xcode project

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.