SlideShare a Scribd company logo
1 of 26
Download to read offline
INTRODUCING CARDIOMERCARI INC.
@KITASUKE
ABOUT ME
MY FUTURE TALKS
> Search APIs and Universal Links in practice
@iOS9 bootcamp
> Introducing new features for watchOS 2
@MOSA software meeting
HEALTHKIT
HealthKit allows apps that provide health
and fitness services
— HealthKit Framework Reference
CLASSES
> HKDevice
> HKSample
> HKObjectType
> HKQuantity
> HKUnit
> HKQuery
HKQUERY
> HKSampleQuery
> HKObserverQuery
> HKAnchoredObjectQuery
> HKStatisticsQuery
> HKStatisticsCollectionQuery
> HKCorrelation
> HKSourceQuery
HEART RATE IN WATCHOS-2-SAMPLER
class HeartRateInterfaceController: WKInterfaceController {
let healthStore = HKHealthStore()
let heartRateType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!
let heartRateUnit = HKUnit(fromString: "count/min")
var heartRateQuery: HKQuery?
override func willActivate() {
super.willActivate()
guard HKHealthStore.isHealthDataAvailable() else { return }
let dataTypes = Set([heartRateType])
healthStore.requestAuthorizationToShareTypes(nil, readTypes: dataTypes) { (success, error) -> Void in
guard success else { return }
}
}
@IBAction func fetchBtnTapped() {
guard self.heartRateQuery == nil else { return }
if self.heartRateQuery == nil {
self.heartRateQuery = self.createStreamingQuery()
self.healthStore.executeQuery(self.heartRateQuery!)
} else {
self.healthStore.stopQuery(self.heartRateQuery!)
self.heartRateQuery = nil
}
}
private func createStreamingQuery() -> HKQuery {
let predicate = HKQuery.predicateForSamplesWithStartDate(NSDate(), endDate: nil, options: .None)
let query = HKAnchoredObjectQuery(type: heartRateType, predicate: predicate, anchor: nil, limit: Int(HKObjectQueryNoLimit)) { (query, samples, deletedObjects, anchor, error) -> Void in
self.addSamples(samples)
}
query.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in
self.addSamples(samples)
}
return query
}
private func addSamples(samples: [HKSample]?) {
guard let samples = samples as? [HKQuantitySample] else { return }
guard let quantity = samples.last?.quantity else { return }
let heartRate = quantity.doubleValueForUnit(heartRateUnit)
}
}
!
CARDIO!HTTPS://GITHUB.COM/KITASUKE/CARDIO
HEALTHKIT WRAPPER
SPECIALIZED FOR
WORKOUT
FEATURES
> Super simple to access HealthKit
> Cuztomizable preferences
> Well-designed for workout app
> Easy way to save workout data in HealthKit
REQUIREMENTS
> watchOS 2.0+
> Swift 2.0+
INSTALLATION
Carthage
github "kitasuke/Cardio"
Add HealthKit entitlements into both containing
iOS app target and WatchKit Extension target
CONTEXT PROTOCOL
public protocol Context {
var activityType: HKWorkoutActivityType { get }
var locationType: HKWorkoutSessionLocationType { get }
var distanceUnit: HKUnit { get }
var activeEnergyUnit: HKUnit { get }
var heartRateUnit: HKUnit { get }
var distanceType: HKQuantityType { get }
var activeEnergyType: HKQuantityType { get }
var heartRateType: HKQuantityType { get }
var shareIdentifiers: [String] { get }
var readIdentifiers: [String] { get }
}
CONTEXT EXTENSION
public extension Context {
public var activityType: HKWorkoutActivityType {
return .Running
}
public var locationType: HKWorkoutSessionLocationType {
return .Outdoor
}
public var distanceUnit: HKUnit {
return HKUnit.meterUnitWithMetricPrefix(.Kilo)
}
public var activeEnergyUnit: HKUnit {
return HKUnit.kilocalorieUnit()
}
public var heartRateUnit: HKUnit {
return HKUnit(fromString: "count/min")
}
...
}
STRUCT CONFORMED CONTEXT
struct CardioContext: Context {
var locationType: HKWorkoutSessionLocationType {
return .Indoor
}
var distanceUnit: HKUnit {
return HKUnit.mileUnit()
}
var shareIdentifiers: [String] {
return []
}
}
INITIALIZATION
let context = CardioContext()
cardio = Cardio(context: context)
AUTHORIZATION
WATCHKIT EXTENSION TARGET
cardio.authorize { result in
}
CONTAINING IOS APP TARGET
func applicationShouldRequestHealthAuthorization(application: UIApplication) {
authorize()
}
UPDATE HANDLERS
cardio.distanceHandler = { distance, total in
}
cardio.activeEnergyHandler = { activeEnergy, total in
}
cardio.heartRateHandler = { heartRate, average in
}
WORKOUT SESSION
cardio.start { result in
}
cardio.end { result in
}
SAVE WORKOUT DATA
cardio.save() { result in
}
FUTURE WORK
> Add more features
> Fully support HealthKit
> Make wrapper for iOS app target
WELCOME YOUR
FEEDBACK &
THOUGHTS !
ANY QUESTIONS?

More Related Content

What's hot

AnDevCon - Tracking User Behavior Creatively
AnDevCon - Tracking User Behavior CreativelyAnDevCon - Tracking User Behavior Creatively
AnDevCon - Tracking User Behavior Creatively
Kiana Tennyson
 
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Aaron Parecki
 
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
Apigee | Google Cloud
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
維佋 唐
 
Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...
Shakir Majeed Khan
 

What's hot (19)

Introduction to SharePoint 2013 REST API
Introduction to SharePoint 2013 REST APIIntroduction to SharePoint 2013 REST API
Introduction to SharePoint 2013 REST API
 
Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Android Intermediatte IAK full
Android Intermediatte IAK fullAndroid Intermediatte IAK full
Android Intermediatte IAK full
 
Building Android apps with Parse
Building Android apps with ParseBuilding Android apps with Parse
Building Android apps with Parse
 
AnDevCon - Tracking User Behavior Creatively
AnDevCon - Tracking User Behavior CreativelyAnDevCon - Tracking User Behavior Creatively
AnDevCon - Tracking User Behavior Creatively
 
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
 
Search API
Search APISearch API
Search API
 
File Repository on GAE
File Repository on GAEFile Repository on GAE
File Repository on GAE
 
Actionview
ActionviewActionview
Actionview
 
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search a...
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
 
Parse Advanced
Parse AdvancedParse Advanced
Parse Advanced
 
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
 
Android Froyo
Android FroyoAndroid Froyo
Android Froyo
 
Amazon Rekognition Workshop
Amazon Rekognition WorkshopAmazon Rekognition Workshop
Amazon Rekognition Workshop
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...
 
Cloud native programming model comparison
Cloud native programming model comparisonCloud native programming model comparison
Cloud native programming model comparison
 

Viewers also liked

Viewers also liked (20)

Tips for better CI on Android
Tips for better CI on AndroidTips for better CI on Android
Tips for better CI on Android
 
Type Safe Assets Handling in Swift
Type Safe Assets Handling in SwiftType Safe Assets Handling in Swift
Type Safe Assets Handling in Swift
 
Objective-C Generics
Objective-C GenericsObjective-C Generics
Objective-C Generics
 
My first tvOS
My first tvOSMy first tvOS
My first tvOS
 
個人で開発したアプリがベスト新着に選ばれた話
個人で開発したアプリがベスト新着に選ばれた話個人で開発したアプリがベスト新着に選ばれた話
個人で開発したアプリがベスト新着に選ばれた話
 
Caffeでお手軽本格ディープラーニングアプリ @potatotips
Caffeでお手軽本格ディープラーニングアプリ @potatotipsCaffeでお手軽本格ディープラーニングアプリ @potatotips
Caffeでお手軽本格ディープラーニングアプリ @potatotips
 
Cocoa勉強会#62-新しい通信クラス群NSURLSessionを使ってみる
Cocoa勉強会#62-新しい通信クラス群NSURLSessionを使ってみるCocoa勉強会#62-新しい通信クラス群NSURLSessionを使ってみる
Cocoa勉強会#62-新しい通信クラス群NSURLSessionを使ってみる
 
Android development at mercari 2015
Android development at mercari 2015Android development at mercari 2015
Android development at mercari 2015
 
WatchKit@potatotips
WatchKit@potatotipsWatchKit@potatotips
WatchKit@potatotips
 
Today & Share Extension@potatotips
Today & Share Extension@potatotipsToday & Share Extension@potatotips
Today & Share Extension@potatotips
 
App extensionでテストコードを書く
App extensionでテストコードを書くApp extensionでテストコードを書く
App extensionでテストコードを書く
 
Share Extension@pixiv
Share Extension@pixivShare Extension@pixiv
Share Extension@pixiv
 
SwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみたSwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみた
 
Swift core
Swift coreSwift core
Swift core
 
WKInterfaceMap on Apple Watch
WKInterfaceMap on Apple WatchWKInterfaceMap on Apple Watch
WKInterfaceMap on Apple Watch
 
Useful and Practical Functionalities in Realm
Useful and Practical Functionalities in RealmUseful and Practical Functionalities in Realm
Useful and Practical Functionalities in Realm
 
Swift Scriptingのすゝめ
Swift ScriptingのすゝめSwift Scriptingのすゝめ
Swift Scriptingのすゝめ
 
Xcode7時代のアプリ配布
Xcode7時代のアプリ配布Xcode7時代のアプリ配布
Xcode7時代のアプリ配布
 
View Monitoring Tips
View Monitoring TipsView Monitoring Tips
View Monitoring Tips
 
Uiテスト@yidev
Uiテスト@yidevUiテスト@yidev
Uiテスト@yidev
 

Similar to Introducing Cardio

ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
DeNA
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
DeNA
 

Similar to Introducing Cardio (20)

Wearables Presentation from Queensland C# Mobile Developers August 2016
Wearables Presentation from Queensland C# Mobile Developers August 2016Wearables Presentation from Queensland C# Mobile Developers August 2016
Wearables Presentation from Queensland C# Mobile Developers August 2016
 
How to make workout app for watch os 2
How to make workout app for watch os 2How to make workout app for watch os 2
How to make workout app for watch os 2
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community
 
Eddystone beacons demo
Eddystone beacons demoEddystone beacons demo
Eddystone beacons demo
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
 
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
We sport architecture_implementation
We sport architecture_implementationWe sport architecture_implementation
We sport architecture_implementation
 
Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your apps
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
Connect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick StreuleConnect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick Streule
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
RxBinding-kotlin
RxBinding-kotlinRxBinding-kotlin
RxBinding-kotlin
 

More from Yusuke Kita

Integrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipelineIntegrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipeline
Yusuke Kita
 

More from Yusuke Kita (20)

Integrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipelineIntegrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipeline
 
Making your own tool using SwiftSyntax
Making your own tool using SwiftSyntaxMaking your own tool using SwiftSyntax
Making your own tool using SwiftSyntax
 
[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline
 
Creating your own Bitrise step
Creating your own Bitrise stepCreating your own Bitrise step
Creating your own Bitrise step
 
Introducing swift-format
Introducing swift-formatIntroducing swift-format
Introducing swift-format
 
Unidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIUnidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUI
 
Open Source Swift Workshop
Open Source Swift WorkshopOpen Source Swift Workshop
Open Source Swift Workshop
 
Contributing to Swift Compiler
Contributing to Swift CompilerContributing to Swift Compiler
Contributing to Swift Compiler
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Writing an interpreter in swift
Writing an interpreter in swiftWriting an interpreter in swift
Writing an interpreter in swift
 
SIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStackSIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStack
 
SIL for First Time Learners
SIL for First Time LearnersSIL for First Time Learners
SIL for First Time Learners
 
var, let in SIL
var, let in SILvar, let in SIL
var, let in SIL
 
SIL for First Time Leaners LT
SIL for First Time Leaners LTSIL for First Time Leaners LT
SIL for First Time Leaners LT
 
How to try! Swift
How to try! SwiftHow to try! Swift
How to try! Swift
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in Swift
 
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfType-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
 
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConType-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
 
Command Line Tool in swift
Command Line Tool in swiftCommand Line Tool in swift
Command Line Tool in swift
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Introducing Cardio

  • 3. MY FUTURE TALKS > Search APIs and Universal Links in practice @iOS9 bootcamp > Introducing new features for watchOS 2 @MOSA software meeting
  • 4. HEALTHKIT HealthKit allows apps that provide health and fitness services — HealthKit Framework Reference
  • 5. CLASSES > HKDevice > HKSample > HKObjectType > HKQuantity > HKUnit > HKQuery
  • 6. HKQUERY > HKSampleQuery > HKObserverQuery > HKAnchoredObjectQuery > HKStatisticsQuery > HKStatisticsCollectionQuery > HKCorrelation > HKSourceQuery
  • 7. HEART RATE IN WATCHOS-2-SAMPLER class HeartRateInterfaceController: WKInterfaceController { let healthStore = HKHealthStore() let heartRateType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)! let heartRateUnit = HKUnit(fromString: "count/min") var heartRateQuery: HKQuery? override func willActivate() { super.willActivate() guard HKHealthStore.isHealthDataAvailable() else { return } let dataTypes = Set([heartRateType]) healthStore.requestAuthorizationToShareTypes(nil, readTypes: dataTypes) { (success, error) -> Void in guard success else { return } } } @IBAction func fetchBtnTapped() { guard self.heartRateQuery == nil else { return } if self.heartRateQuery == nil { self.heartRateQuery = self.createStreamingQuery() self.healthStore.executeQuery(self.heartRateQuery!) } else { self.healthStore.stopQuery(self.heartRateQuery!) self.heartRateQuery = nil } } private func createStreamingQuery() -> HKQuery { let predicate = HKQuery.predicateForSamplesWithStartDate(NSDate(), endDate: nil, options: .None) let query = HKAnchoredObjectQuery(type: heartRateType, predicate: predicate, anchor: nil, limit: Int(HKObjectQueryNoLimit)) { (query, samples, deletedObjects, anchor, error) -> Void in self.addSamples(samples) } query.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in self.addSamples(samples) } return query } private func addSamples(samples: [HKSample]?) { guard let samples = samples as? [HKQuantitySample] else { return } guard let quantity = samples.last?.quantity else { return } let heartRate = quantity.doubleValueForUnit(heartRateUnit) } }
  • 8. !
  • 11. FEATURES > Super simple to access HealthKit > Cuztomizable preferences > Well-designed for workout app > Easy way to save workout data in HealthKit
  • 13. INSTALLATION Carthage github "kitasuke/Cardio" Add HealthKit entitlements into both containing iOS app target and WatchKit Extension target
  • 14. CONTEXT PROTOCOL public protocol Context { var activityType: HKWorkoutActivityType { get } var locationType: HKWorkoutSessionLocationType { get } var distanceUnit: HKUnit { get } var activeEnergyUnit: HKUnit { get } var heartRateUnit: HKUnit { get } var distanceType: HKQuantityType { get } var activeEnergyType: HKQuantityType { get } var heartRateType: HKQuantityType { get } var shareIdentifiers: [String] { get } var readIdentifiers: [String] { get } }
  • 15. CONTEXT EXTENSION public extension Context { public var activityType: HKWorkoutActivityType { return .Running } public var locationType: HKWorkoutSessionLocationType { return .Outdoor } public var distanceUnit: HKUnit { return HKUnit.meterUnitWithMetricPrefix(.Kilo) } public var activeEnergyUnit: HKUnit { return HKUnit.kilocalorieUnit() } public var heartRateUnit: HKUnit { return HKUnit(fromString: "count/min") } ... }
  • 16. STRUCT CONFORMED CONTEXT struct CardioContext: Context { var locationType: HKWorkoutSessionLocationType { return .Indoor } var distanceUnit: HKUnit { return HKUnit.mileUnit() } var shareIdentifiers: [String] { return [] } }
  • 17. INITIALIZATION let context = CardioContext() cardio = Cardio(context: context)
  • 18. AUTHORIZATION WATCHKIT EXTENSION TARGET cardio.authorize { result in } CONTAINING IOS APP TARGET func applicationShouldRequestHealthAuthorization(application: UIApplication) { authorize() }
  • 19. UPDATE HANDLERS cardio.distanceHandler = { distance, total in } cardio.activeEnergyHandler = { activeEnergy, total in } cardio.heartRateHandler = { heartRate, average in }
  • 20. WORKOUT SESSION cardio.start { result in } cardio.end { result in }
  • 22.
  • 23.
  • 24. FUTURE WORK > Add more features > Fully support HealthKit > Make wrapper for iOS app target