Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6465] Hyperloop - HealthKit requestAuthorizationToShareTypes is not a function

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop, Titanium SDK & CLI
Labelsios
ReporterPetr Malakhaltsev
AssigneeShak Hossain
Created2020-01-01T21:36:07.000+0000
Updated2020-01-29T20:24:31.000+0000

Description

I'm trying to authorize HealthKit via Hyperloop to query height of the user, so I run the following code:
import {
  HKHealthStore,
} from 'HealthKit';

if (HKHealthStore.isHealthDataAvailable()) {
  Ti.API.log('available');
} else {
  Ti.API.log('not available');
}

let hk = new HKHealthStore();
hk.requestAuthorizationToShareTypes([], [], function() {});
It does show "available" message, so I assume that heath data is available, but then it throughs an error "hk.requestAuthorizationToShareTypes is not a function", I've tried "swift-like" function "requestAuthorization" as well, but same result. p.s. Is there any way to get available functions from Hyperloop?

Comments

  1. Jan Vennemann 2020-01-06

    I guess you are trying to use [requestAuthorizationToShareTypes:readTypes:completion:](https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorizationtosharetypes?language=objc). According to the conventions for [method names](https://docs.appcelerator.com/platform/latest/#!/guide/iOS_Hyperloop_Programming_Guide-section-src-46253491_iOSHyperloopProgrammingGuide-Namedmethods), this is the Hyperloop equivalent:
       hk.requestAuthorizationToShareTypesReadTypesCompletion([], [], function() {});
       
  2. Petr Malakhaltsev 2020-01-06

    Yes, that's true. It was my mistake that I missed this part of the iOS Hyperloop Programming Guide. But now, after I follow your suggestion it doesn't seem to do anything. No error, no authorization popup.
       let hk = new HKHealthStore();
       let height = HKObjectType.quantityTypeForIdentifier('HKQuantityTypeIdentifierHeight');
       hk.requestAuthorizationToShareTypesReadTypesCompletion([height], [height], function completion(success, error) {
         Ti.API.log('success');
       });
       
  3. Rene Pot 2020-01-07

    [~pmalakhaltsev] have you configured the correct plist keys? Like NSHealthShareUsageDescription and NSHealthUpdateUsageDescription?
  4. Petr Malakhaltsev 2020-01-07

    Yes, I have both keys in tiapp.xml
               <key>NSHealthShareUsageDescription</key>
               <string>Share data description</string>
               <key>NSHealthUpdateUsageDescription</key>
               <string>Access data description</string>
       
    Also I have "entitlements" section:
           <entitlements>
             <dict>
               <key>com.apple.developer.healthkit</key>
               <true/>
               <key>com.apple.developer.healthkit.access</key>
               <array/>
             </dict>
           </entitlements>
       
    Besides this I've tried to clean the project and rebuild it. Doesn't help.
  5. Rene Pot 2020-01-28

    [~pmalakhaltsev] perhaps you have the same issue as [this guy?](https://stackoverflow.com/questions/26010554/requestauthorizationtosharetypes-method-not-displaying-permissions-prompt-in-ios)
  6. Petr Malakhaltsev 2020-01-29

    @topener, that's unlikely as: 1. I pass not a string but (hopefully) quanityType
       var height = HKObjectType.quantityTypeForIdentifier("HKQuantityTypeIdentifierHeight");
       
    2. I initialize healthStore as an object (according to Hyperloop guide):
       var hk = HKHealthStore.alloc().init();
       // or
       var hk = new HKHealthStore();
       
    So I can't spot any visible mistake in the code ..

JSON Source