i'm working on following code, has steps of person walking. every time step 1 view counter stops. working somotiondetector.
note: when printing console steps continues function changing views.
#import "somotiondetector.h" #import "sostepdetector.h" @interface contarpasos ()<somotiondetectordelegate> { int stepcount; } @property (weak, nonatomic) iboutlet uilabel *speedlabel; @property (weak, nonatomic) iboutlet uilabel *stepcountlabel; @property (weak, nonatomic) iboutlet uilabel *motiontypelabel; @property (weak, nonatomic) iboutlet uilabel *isshakinglabel; @end @implementation contarpasos - (void)viewdidload { [super viewdidload]; __strong contarpasos *weakself = self; [somotiondetector sharedinstance].motiontypechangedblock = ^(somotiontype motiontype) { nsstring *type = @""; switch (motiontype) { case motiontypenotmoving: type = @"no estas moviendote"; break; case motiontypewalking: type = @"caminando"; break; case motiontyperunning: type = @"corriendo"; break; case motiontypeautomotive: type = @"automotive"; break; } weakself.motiontypelabel.text = type; }; [somotiondetector sharedinstance].locationchangedblock = ^(cllocation *location) { weakself.speedlabel.text = [nsstring stringwithformat:@"%.2f km/h", [somotiondetector sharedinstance].currentspeed * 3.6f]; }; [somotiondetector sharedinstance].accelerationchangedblock = ^(cmacceleration acceleration) { bool isshaking = [somotiondetector sharedinstance].isshaking; weakself.isshakinglabel.text = isshaking ? @"corriendo":@"no corriendo"; }; if (system_version_greater_than_or_equal_to(@"7.0")) { [somotiondetector sharedinstance].usem7ifavailable = yes; //use m7 chip if available, otherwise use lib's algorithm } [[somotiondetector sharedinstance] startdetection]; [[sostepdetector sharedinstance] startdetectionwithupdateblock:^(nserror *error) { if (error) { nslog(@"%@", error.localizeddescription); return; } stepcount++; weakself.stepcountlabel.text = [nsstring stringwithformat:@"pasos: %d", stepcount]; nslog(@"always printed on console not in view: %d", stepcount); }]; }
Comments
Post a Comment