IOS: Share data App Groups between iphone and Apple Watch

Source: Internet
Author: User

we can share data between iphone and Apple Watch via app groups. Here's how:

The first thing to do is add a new app group to Dev Center:

Next, create a new single view application, named Sharingdatademo:

Add three controls to the main interface: TextField, button, and label.

Use Nsuserdefaults to save user-entered content in a button's Click event:


Note Suitename must match the identifier ID of the app group defined in Dev Center.

Next add Watch: Select the File-new-target-watchkit App:

Add two controls to watch's main interface: Label and button.

Use Nsuserdefaults in the Click event of a button to read the data saved in the previous step and display it on the label:

The final step, and the key step, is to set up the iphone app and watch app to the same group, which is missing and the data cannot be shared.
Note that the iphone app and watch app are set up so that you don't miss the Watch app settings.

Effect:


IOS: Share data App Groups between iphone and Apple Watch

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.