Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5579] HKHealthStore requestAuthorizationToShareTypes is not a function

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNot Our Bug
Resolution Date2018-02-07T15:05:08.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
Labelsn/a
ReporterYanko Valera
AssigneeShak Hossain
Created2018-02-07T13:39:18.000+0000
Updated2018-02-07T15:05:48.000+0000

Description

While trying to get permissions from HealthKit, the HKHealthStore instance is not allowing me to call the requestAuthorizationToShareTypes function. Code below
var HKHealthStore = require('HealthKit/HKHealthStore');

var HKObjectType = require('HealthKit/HKObjectType');

var HKCategoryTypeIdentifierSleepAnalysis = require("HealthKit").HKCategoryTypeIdentifierSleepAnalysis;

var NSSet = require('Foundation/NSSet');

exports.start = function() {
    if (HKHealthStore.isHealthDataAvailable()) {
        var healthStore = HKHealthStore.alloc().init();

        var shareTypes = NSSet.set();

        var readTypes = NSSet.setWithObject(HKObjectType.categoryTypeForIdentifier(HKCategoryTypeIdentifierSleepAnalysis));

        healthStore.requestAuthorizationToShareTypes(shareTypes, readTypes, function(success, error) {

        });
    }
}

Comments

  1. Hans Knöchel 2018-02-07

    Hey there! Sorry, but this is not valid. Regarding the [docs](https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorizationtosharetypes), the correct call is
       var healthStore = new HKHealthStore(); // Same as alloc().init();
       healthStore.requestAuthorizationToShareTypesReadTypesCompletion(shareTypes, readTypes, function(success, error)) {
         // Handle result
       });
       
    Basically, you just need to ensure that all arguments are concatenated and it will match it.

JSON Source