詳細検索

The future of apps that link smartwatches and MBass is bright

Avatar
by 吉亨斗
4 min read

The future of apps that link smartwatches and MBass is bright
Translated from 日本語 • View original

About Smartwatch Apps

全画面_2015_07_21_15_14

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

  1. Create a new project (Single View Application) for IOS.
  2. Select Xcode > File > New > Target
  3. Add the WatchKit App

add watchkitScreen specifications

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.

Interface_storyboardImplement CheckInController

  1. Import the WatchKit framework.
  2. Inherit the WKI InterfaceController class.
  3. Implement the willActivate method, which is executed first when CheckInController is called.
  4. Get the current time.
  5. **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.

job_time_recoder_xcodeproj

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.

Edit_Your_App___Parse 2

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

time_history___ParseImplement the iPhone app side

  1. Import Parse Framework
  2. Define Parse's Application ID for id and Parse's Client Key for key.
  3. Implement the receiver side of the WKInterfaceController.openParentApplication method in Contorller in Watchkit Extention
  4. Get parameters (type, time)
  5. **Here is the point! **Set the application ID.
  6. Generate Parse Objects
  7. Set the value to be registered in Parse
  8. 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!

Click the Check In button

Apple_Watch_38mm

Apple_Watch_38mm 2

Apple_Watch_38mm

Apple_Watch_38mm 2

Parse Data Review

time_history___Parse

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>

 

 

 

 

Related Articles