Wearable Tech Preview: Apple Watch and PubNub
The Apple Watch SDK has been available for XCode for a few months as part of iOS 8.3. Based on the tremendous initial interest, it seems like Apple Watch will be a platform with several million of connected devices coming online by the end of the year and beyond. This latest addition to Apple’s product line aims to make our daily lives easier and more interactive via lightweight, minimal activities and information display.
The Apple Watch Framework is beginning to emerge, currently as part of iOS 8.3 SDK. In this article, we will review a little of how you can make the best of the Apple Watch and create amazing apps.
Where does Apple Watch fit in the Internet Of Things?
As the world of connected objects grows, the Apple Watch wearable device has a unique role in being constantly connected to a user’s wrist (and fingertips).
The Internet of Things allows you to interact with all types of basic devices; turning on the light, opening the garage door, checking the temperature in your house or starting the heater to name a few. Each device serves one of two purposes. They are either sensors, or actuators. You either read the temperature, or activate the motor which opens the garage door. None of these actions require a large screen, and none need a complicated dashboard of controls. A simple button is enough!
This points to Apple Watch having a perfect form factor and being a more practical device (always around your wrist) to control an entire landscape of connected devices.
How Will You Use Your Apple Watch?
One very important key to a successful app is to make life easier with minimal distractions. No need to think about complicated systems. Just ask yourself what a computer strapped around your arm could do for you.
Let’s think about how one would use the Apple Watch based on what it has to provide:
- A small display
- Easily accessible on the wrist
- On the body a majority of the time
These are just a handful of domains where an Application could interact perfectly with the Apple Watch:
- Health Applications: around the wrist, the watch is a great source of health-related data
- Transportation: following you everywhere, it can compute, share plenty of information and interact with your surrounding world in real-time.
- The Internet Of Things: perfect window to all your connect devices
In this context, PubNub is extremely useful when it comes to developing connected objects and real-time applications. From transportation apps to controlling the living room, PubNub takes care of the magic (aka: powerful infrastructure you don’t have to build) for real-time and multi-device interaction.
Current State of the Apple Watch SDK and Features
Hardware: iBeacon For All!
iBeacon allows Apple Watch to have short length interaction with all types of connected devices. However, the iBeacon protocol only allows one-way communication. This means you cannot have a bidirectional interaction with devices using iBeacon, but rather, only one device triggering events on the other. PubNub allows you to make smarter beacons, enabling a two-way communication over WiFi. This keeps the low consumption, of the iBeacon, even as it stays on indefinitely, while enhancing the communication your device at all times.
For example, iBeacon can trigger alerts on your phone if you walk past a coffee shop with a personalized message or discount to the device wearer, trigger lights in a home to turn off and on based on proximity, or stream traffic alerts when a user enters a garage.
Combining the Internet of Things with iBeacons has the potential to unleash some pretty amazing applications.
Software: A Slim SDK
Currently, most of the information relies on the architecture of an Apple Watch app, while most of the computing should be on your phone. The watch will only hold the views and interactive elements. Apple’s WatchKit Framework Documentation enumerates the interactive elements the developer will be allowed to use.
We found the voice text input button very exciting. You can find some example’s of how to use PubNub for your chat and messaging applications on our blog. Integrating these to your Apple Watch app should not be to complicated, and will satisfy your users thanks to the voice input to write message.
The Programming Guide mostly explains three basic elements from which the user interacts with his watch:
- Glances, which are not interactive. You can you those to allow the user to read the current temperature in his house for example. You’ll be able to access and update this information with PubNub.
- Notifications, which can be triggered anytime. Your app could have a PubNub message trigger the notification when a user is walking past your store for example.
- WatchKit Apps, for example, the user will be able to turn the lights of his house off
Now, let’s get started with PubNub.
PubNub and Apple Watch
You can picture a PubNub channel like a room. When you want to say something to the people in the room, you publish a message. On the other hand, if you want to listen to what people are saying in the room, you simply subscribe to the channel. Whenever something happens in the room, such as people leaving or entering, you will be notified by using callbacks.
Now, imagine your car is subscribed to a channel as soon as it starts. You can have a connected object, like a light or the garage door, listening for an event. When that car turns on, it communicates over a channel with the garage door in real time, and the action is triggered (in this case, opening the garage door).
With PubNub Data Streams, you can connect all types of objects regardless of their manufacturer or the programming language. For proper compatibility between devices, you can share JSON messages over your channel.
Let’s look at an example of an Apple Watch using PubNub. Your Apple Watch app uses the Voice Option to send text messages via PubNub. These text messages can be parsed, and the application looks for action-related words and device names. “Turn off the lights” could be parsed and both “turn off” and “lights” would trigger the lights.
PubNub is already integrated into Apple Watch applications, running for thousands of users simultaneously in the real world. Sports social network Sportlobster uses PubNub to deliver real-time push notifications to Apple Watch users. Users can add teams on their iOS mobile application, and live push notifications are delivered in real time via PubNub with score and game updates.
Enough words, let’s jump into some code.
Let’s start by adding PubNub to your project. For that, CocoaPods is your friend. Check out their website for detailed information on how to use it. To ease out the for you, this is how your podfile should look like:
You can make sure you are using the latest version of PubNub here.
Use Objective-C Libraries in Swift
The PubNub iOS SDK library is written in Objective-C, but we are coding in swift. All you need to do now is to build a bridging header. Create a new Objective-C header in your project called YourProject-Bridging-Header.h for good practice, and type:
Now in your project’s configuration panel, go to build settings and scroll down to the “Swift Compiler – Code Generation” section. Set the “install Objective-C Bridging Header” to Yes and in “Objective-C Bridging Header” type the path from your project’s root directory to your bridging header.
It’ll be something like “YourProject/YourProject-Bridging-Header.h”.
That’s it! You are ready to roll! Check out the iOS SDK Library for more on implementing PubNub pub/sub messaging and additional features. You’ll also find plenty of sample apps to get started on the PubNub Blog. We look forward to seeing how you connect wearables and the Internet of Things!