watchkit - How to make HKworkoutsession always an active workout session -


i'm working on apple watch app , i'm using hkworkoutsession access heart rate data sample.

in newest watchos2 beta3 release bug "during active workout session, new heart rate samples not generated when screen off." fixed.

my question how set hkworkoutsession "active work out session" keep getting heart rate sample need.

thanks ryan

code following how start or stop workout session.

let healthstore = hkhealthstore() healthstore.startworkoutsession(workoutsession) {   (result: bool, error: nserror?) -> void in }  healthstore.stopworkoutsession(workoutsession) {   (result: bool, error: nserror?) -> void in } 

there hkworkoutsessiondelegate notifies session state.

protocol hkworkoutsessiondelegate : nsobjectprotocol {  func workoutsession(workoutsession: hkworkoutsession,   didchangetostate tostate: hkworkoutsessionstate,   fromstate: hkworkoutsessionstate, date: nsdate)  func workoutsession(workoutsession: hkworkoutsession,   didfailwitherror error: nserror) } 

[edited] 2015/08/31

objc version

hkworkoutsession *workoutsession = [[hkworkoutsession alloc] initwithactivitytype:hkworkoutactivitytyperunning locationtype:hkworkoutsessionlocationtypeoutdoor]; workoutsession.delegate = self;  hkhealthstore *healthstore = [hkhealthstore new]; [healthstore startworkoutsession:workoutsession];  [healthstore stopworkoutsession:workoutsession]; 

hkwrokoutsessiondelegate

- (void)workoutsession:(hkworkoutsession *)workoutsession   didchangetostate:(hkworkoutsessionstate)tostate          fromstate:(hkworkoutsessionstate)fromstate               date:(nsdate *)date;  - (void)workoutsession:(hkworkoutsession *)workoutsession didfailwitherror:(nserror *)error; 

caution: there change of method name latest version, watch os 2 beta 5.

stopworkoutsession has changed endworkoutsession.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -