Coder Social home page Coder Social logo

Comments (6)

EddyVerbruggen avatar EddyVerbruggen commented on July 19, 2024

Hi, it's actually in seconds, see this debugging screenshot of XCode 6.2, running on my iPhone 6 /w iOS 8.2:

schermafbeelding 2015-03-12 om 16 47 00

Can you send me the JS code you used to save the workout?

from healthkit.

gylippus avatar gylippus commented on July 19, 2024

Admittedly I'm not 100% up to date with the latest version, but here is what I am using:

var startDate = new Date(); //This is created at the beginning of the workout
var minutesCompleted = 5;
var energyBurn = 40;
window.plugins.healthkit.saveWorkout({
     'activityType': 'HKWorkoutActivityTypeFunctionalStrengthTraining',
     'quantityType': null,
     'startDate': $scope.startDate,
     'endDate': null,
     'duration': minutesCompleted * 60,
     'energy': energyBurn,
     'energyUnit': 'kcal',
     'distance': null,
     'distanceUnit': 'm'
     },
     function(msg){
      console.log('HealthKit success: ' + msg);
     },
     function(msg){
      console.log('HealthKit error: ' + msg);
     }
);

Doesn't startDate.timeIntervalSince1970 in line 121 of what is in mater now return milliseconds though which we are then adding seconds to?

I do need to test on the updated Health.m file though, but I was just curious that it seemed like it was subtracting seconds from milliseconds. I am still on this old code:

    int duration = 0;
    NSNumber* startTime  = [args objectForKey:@"startTime"];
    NSTimeInterval _startInterval = [startTime doubleValue] / 1000; // strip millis
    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:_startInterval];

    NSDate *endDate;
    if ([args objectForKey:@"duration"]) {
        duration = [[args objectForKey:@"duration"] intValue];
        endDate = [NSDate dateWithTimeIntervalSince1970:_startInterval + duration];
    } else if ([args objectForKey:@"endTime"]) {
        NSNumber* endTime = [args objectForKey:@"endTime"];
        NSTimeInterval _endInterval = [endTime doubleValue] / 1000; // strip millis
        endDate = [NSDate dateWithTimeIntervalSince1970:_endInterval];
    } else {
        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no duration or endDate was set"];
        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
        return;
    }

from healthkit.

EddyVerbruggen avatar EddyVerbruggen commented on July 19, 2024

timeIntervalSince1970 is in seconds so it must be something else. Please update and let me know what you find out..

from healthkit.

gylippus avatar gylippus commented on July 19, 2024

Thanks for the verification Eddy, I put some breakpoints into Xcode and it is a mistake on my part for what I am passing in minutes. Never really mattered until 8.2 so I never really saw the time an output.

from healthkit.

EddyVerbruggen avatar EddyVerbruggen commented on July 19, 2024

👍

from healthkit.

desmeit avatar desmeit commented on July 19, 2024

@gylippus I tested your code with version 0.5.6 but its not working. I get:

*** Terminating app due to uncaught exception '_HKObjectValidationFailureException', reason: 'Invalid data type (null)'

@EddyVerbruggen Do you have an Idea? I tried exactly the same code like gylippus.

from healthkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.