About Smartwatch Apps

Although not as much as smartphones, the penetration rate of smartwatches worldwide is rapidly increasing. Taking the Apple Watch as an example, it seems that 36 million units were sold in one year. http://japan.cnet.com/news/business/35064877/
In addition, Apple and Google have a platform for developing smartwatch apps at the center, so you can easily create apps. The time to meet the user's requirements with a smartwatch without having to take the smartphone out of your pocket is just around the corner.
So I decided to make an app that links smart watch (Apple Watch) and MBass (Parse). Learn more about Parse
Let's Make an App
I would like to introduce how easy it is to create an app to clock in from a smart watch. This is explained to those with IOS development experience, but it is a level that even beginners can understand quickly, so please read it to the end.
Development Environment
- Xcode 6.4
- IOS 8.4
- Swift
Project Creation
- Create a new project (Single View Application) for IOS.
- Select Xcode > File > New > Target
- Add the WatchKit App

When you click the Check In button, the interface on screen 1 is called. Create a CheckInController file under the WatchKit Extention folder and link it to screen 1. *The same goes for Check Out.

- Import the WatchKit framework.
- Inherit the WKI InterfaceController class.
- Implement the willActivate method, which is executed first when CheckInController is called.
- Get the current time.
- **This is the point! ** Communicate the processing details to the parent app (iPhone).
import WatchKit // <1>
import Foundation
class CheckInController: WKInterfaceController { // <2>
@IBOutlet weak var message: WKInterfaceLabel!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
message.setText("Success! Check In");
}
override func willActivate() { // <3>
// This method is called when watch view controller is about to be visible to user
super.willActivate()
Get the current time // <4>
let now = NSDate()
let dateFormater = NSDateFormatter()
dateFormater.dateFormat = "yyyy/MM/dd HH:mm"
let request = [
"type": "1",
"time": dateFormater.stringFromDate(now)as String
]
let isSuccess = WKInterfaceController.openParentApplication(request,reply:nil) // <5>
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
Deploy the Parse SDK Visit the SDK download page to download the SDK for IOS.
Add Parse.framework and Bolts.framework from the frameworks you just downloaded from Linked Frameworks and Libraries.

I'll also add the following frameworks that the Parse framework depends on:
- SystemConfiguration.framework
- AudioToolbox.framework
- libsqlite3.dylib
Parse Access Key
Parse account creation and app creation will be omitted as they will appear immediately from Google search.
Open the Settings > Keys screen and note the Application ID and Client Key.

Let's add the following columns to be used in this app.
- user_id (Number)
- type (String) Check In/Out Flags to distinguish
- time (Date) Check In/Out time

- Import Parse Framework
- Define Parse's Application ID for id and Parse's Client Key for key.
- Implement the receiver side of the WKInterfaceController.openParentApplication method in Contorller in Watchkit Extention
- Get parameters (type, time)
- **Here is the point! **Set the application ID.
- Generate Parse Objects
- Set the value to be registered in Parse
- Register with Parse
import UIKit
import Parse // <1>
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// <2>
let id = "xxxxx"
let key = "xxxxx"
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo:[NSObject:AnyObject]?, reply:(([NSObject:AnyObject]!) ->Void)!) { // <3>
Get <4>messages from request
var dic = userInfo as! Dictionary<String,String>
var type = dic["type"]
var time = dic["time"]
var date_fomatter = NSDateFormatter()
date_fomatter.dateFormat = "yyyy/MM/dd HH:mm"
Data Registration
Parse.setApplicationId(self.id, clientKey:self.key) // <5>
var time_history = PFObject(className: "time_history") // <6>
// <7>
time_history["user_id"] = 1 as Int
time_history["type"] = type
time_history["time"] = date_fomatter.dateFromString(time!)
time_history.saveInBackgroundWithBlock{ // <8>
(success: Bool, error: NSError?) -> Void in
if (success) {
println("Success! input Data. Type is \(type) And Time is \(time)")
}else {
println("Failed! input Data. Type is \(type) And Time is \(time)")
}
}
Examining the ViewController
let vc = self.window?. rootViewController as? ViewController
vc?. setMessage(type!, time: time!)
}
That's it!
Let's launch the app!
Thoughts
Developing apps with Apple Watch and Parse was easier than I expected. This article only introduced data registration, but you can also acquire and analyze the data registered in Parse on the web server side.
I also thought that data from not only wearable devices but also IoT devices can be collected using Parse, and anything can be connected! If we analyze and process that data, we can obtain various added values.
As a developer, I am grateful that I was born into a blessed world where I can quickly create what I think! :)
</8></7></6></5></String,String></4></3></2></1>
</5></4></3></2></1>