Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the list of tasks from the iPhone onto the Apple Watch #23

Open
1 of 5 tasks
sohilpandya opened this issue Dec 9, 2016 · 2 comments
Open
1 of 5 tasks

Show the list of tasks from the iPhone onto the Apple Watch #23

sohilpandya opened this issue Dec 9, 2016 · 2 comments

Comments

@sohilpandya
Copy link
Member

sohilpandya commented Dec 9, 2016

Now that a user has the ability to add/edit/delete tasks on the iPhone, The next step is to show these tasks on the Apple Watch. (#21)

WatchKit Connectivity Framework

  • Coordinate activities between your iOS app and your corresponding Watch app.

WCSession Class

  • This class helps coordinate communications between the paired iPhone and Apple Watch, for this communication to take place, we need to instantiate the WCSession classes in both the iPhone and Watch controllers

Initially, I'll research into the best way to tackle the transference of data using Watchkit Connectivity. I've found 4 ways to tackle this. I'll be methods and the pros/cons of using each below

  • updateApplicationContext - sends a small amount of information, this information should be used to update interface. ( warningeach successive updateApplicationContext call replaces the data sent by the previous call )
  • transferUserInfo(_:) - sends the specified data dictionary to the paired device ( this content of the dictionary must not be nil.
    • This method should be called when you want to transfer dictionary of data. This method seems to be synchronous as each call is queued up and delivered one after another.
    • This transfer continues even if the app is suspended This is cool!
    • Another Method linked to this is called transferCurrentComplicationUserInfo(_:) - This method sends complication data from the iPhone to the Watch (Unidirectional) [Important note Only transfer complication data]
  • transferFile(_:metadata:) Sends the file and dictionary to the paired device.
    • Files are transferred asynchronously on a background thread. If the file cannot be sent, then it calls the session:fileTransfer:didFinishWithError: to report the error.
    • Important This method can only be called when the session is active. If it is called when the session is inactive/deactivated then it returns an error.
  • sendMessage(_:replyHandler:errorHandler:) sends a message immediately to the paired device. (used in version 0.1 of the app) Has a related receiver method
    • Messages are queued and received on the other device in the order they were sent. (messages are sent asynchronously, so the method returns immediately)
    • sends a dictionary, optional replyHandler will receive a response if present, ErrorHandler for handling errors!
    • Important This method can only be called when the session is active. If it is called when the session is inactive/deactivated then it returns an error.
    • From The API Reference Documentation

    Calling this method from your WatchKit extension while it is active and running wakes up the corresponding iOS app in the background and makes it reachable. Calling this method from your iOS app does not wake up the corresponding WatchKit extension. If you call this method and the counterpart is unreachable (or becomes unreachable before the message is delivered), the errorHandler block is executed with an appropriate error. The errorHandler block may also be called if the message parameter contains non property list data types.

@sohilpandya
Copy link
Member Author

sohilpandya commented Dec 12, 2016

I've managed to get transferUserInfo to work using the following.

  • Phone

screen shot 2016-12-12 at 14 19 05

screen shot 2016-12-12 at 14 19 11

Here I've created a session as well as a method that transfers information to the watch -> transferUserInfo, I then run the method when the phone view loads.

  • Watch

screen shot 2016-12-12 at 14 20 40

In the watch controller, we've added a method didReceiveUserInfo which receives the information.

Issues

As you can see I've managed to get the dictionary across to the phone.
screen shot 2016-12-12 at 15 29 18

But in it's current form, I am unable to access each individual item in the array.

Issues

So the next steps for me:

  • Figure out the best way to extract the array of tasks
  • Display the individual tasks on the watch in a list?

@sohilpandya
Copy link
Member Author

Update

I've managed to get the tasks from the iPhone to show up on the Apple Watch 🎉

screen shot 2016-12-13 at 11 52 14

Once the dictionary is received by the Watch, we are just iterating over it and if key name is "tasks" then I can assign the value to an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant