Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26483] Hyperloop - iOS: Exclude platform unsupported methods from metabase

GitHub Issuen/a
TypeBug
PriorityCritical
StatusResolved
ResolutionFixed
Resolution Date2018-11-01T20:02:39.000+0000
Affected Version/sHyperloop 3.1.3
Fix Version/sHyperloop 3.2.0
ComponentsHyperloop, iOS
Labelsn/a
ReporterJoachim Mollin
AssigneeJan Vennemann
Created2018-10-15T14:53:39.000+0000
Updated2018-11-08T23:11:40.000+0000

Description

*Steps to reproduce the behavior*
const HKHealthStore = require('HealthKit/HKHealthStore');
console.log(isHealthDataAvailable: ${HKHealthStore.isHealthDataAvailable()});
*Actual behavior* The build fails with a linker error due to usage of symbols that are not available on iOS *Expected behavior* The build is successful and HealthKit is usable via Hyperloop

Attachments

FileDateSize
.log2018-10-15T14:53:46.000+00004146209
diagnostic3820464935909926844.log2018-10-15T14:53:57.000+0000498754

Comments

  1. Jan Vennemann 2018-10-24

    Both should work but it appears there is an issue with certain parts of the HealthKit framework only being available on watchOS.
  2. Joachim Mollin 2018-10-24

    if I try: var HealthKit = require('HealthKit/HKHealthStore'); get the info after try to compile directly in Xcode HKWorkoutSession' is unavailable: not available on iOS/
  3. Jan Vennemann 2018-10-24

    Yes, that's exactly the issue we will fix in this ticket. Sorry, there is currently no workaround for that.
  4. Joachim Mollin 2018-10-24

    The workaround ist possible by open HealthKit.m in an Xcode editor and delete the lines after hyperloop does its compiling and before Xcode compiling Not good but possible. Nevertheless I struggle with the next steps. Maybe you can help: console.log (HKHealthStore.isHealthDataAvailable()); var healthStore = new HKHealthStore; console.log (healthStore.bloodType()); but get always [ERROR] : Script Error { [ERROR] : column = 39; [ERROR] : line = 24; [ERROR] : message = "healthStore.bloodType is not a function. (In 'healthStore.bloodType()', 'healthStore.bloodType' is undefined)"; [ERROR] : sourceURL = "file:///Users/mollin/Library/Developer/CoreSimulator/Devices/AD860109-8C75-46A2-985F-098761AA8475/data/Containers/Bundle/Application/117FCE39-3893-4EF9-9045-F395564C02F4/mcx%20alexa.app/ui/common/app_ui_healthkit.js"; [ERROR] : stack = " at start@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/AD860109-8C75-46A2-985F-098761AA8475/data/Containers/Bundle/Application/117FCE39-3893-4EF9-9045-F395564C02F4/mcx%20alexa.app/ui/common/app_ui_healthkit.js:24:39)\n at global code@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/AD860109-8C75-46A2-985F-098761AA8475/data/Containers/Bundle/Application/117FCE39-3893-4EF9-9045-F395564C02F4/mcx%20alexa.app/app.js:35:20)"; [ERROR] : }
  5. Jan Vennemann 2018-10-24

    Well, that works, but it's very unpractical since you always need to change it if the hyperloop code is regenerated. Anyway, to continiue you need to look at the Objcetive-C API, you used is the Swift method name. It should be something like healthStore.bloodTypeWithError(null)
  6. Joachim Mollin 2018-10-24

    Thanks for help; as I'm not familiar with object-c. I am able to use simple functions as you describe. Can you help me to implement - (void)requestAuthorizationToShareTypes:(NSSet *)typesToShare readTypes:(NSSet *)typesToRead completion:(void (^)(BOOL success, NSError *error))completion; I always get the info that requestAuthorizationToShareTypes is not a function would be very helpful as I have soon a presentation for apple healthcare people in Germany
  7. Jan Vennemann 2018-10-25

    Please read the docs and check the hyperloop-examples app which should point you in the right direction. You will have to create the NSSet instances, fill them with the types you want and then you should be able to call healthStore.requestAuthorizationToShareTypesReadTypesCompletion(typesToShare, typesToRead, function(success, error) {}). I can answer to your specific questions but i cannot provide a complete working example. However, i'm working on a fix for the internal Hyperloop issue so you don't have to patch files manually.
  8. Joachim Mollin 2018-10-27

    Hi Jan, thanks for that help. Although its not easy to patch Hyperloop files manually, I was able to call the method without getting an error. The only problem is to get the typesToShare and typesToRead. I tried this under others but got null as result var readTypes = [require('HealthKit/HKObjectType').HKCharacteristicTypeIdentifierDateOfBirth]; Maybe some last hint from you how to solve Best regards Joachim Mollin
  9. Jan Vennemann 2018-10-30

    Hyperloop does not automatically convert between js arrays and the native counterparts because there are just too many possible target classes that act as collections. Instead you have to explicitly create an NSSet or NSMutableSet as you would in Objective-C.
       const HKObjectType = require('HealthKit/HKObjectType');
       const HKQuantityTypeIdentifierBodyMassIndex = require('HealthKit').HKQuantityTypeIdentifierBodyMassIndex;
       const typesToWrite = new NSMutableSet(); // short for NSMutableSet.alloc().init()
       typesToWrite.addObject(HKObjectType.characteristicTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex));
       // ...
       
  10. Joachim Mollin 2018-11-01

    Tried again a lot. Ended up with this error. What am I doing wrong? const HKObjectType = require('HealthKit/HKObjectType'); const HKQuantityTypeIdentifierBodyMassIndex = require('HealthKit/HKQuantityType'); const NSMutableSet = require('Foundation/NSMutableSet'); const typesToWrite = new NSMutableSet(); // short for NSMutableSet.alloc().init() typesToWrite.addObject(HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex)); got always this [ERROR] : *** -[__NSSetM addObject:]: object cannot be nil [ERROR] : Script Error { [ERROR] : column = 26; [ERROR] : description = "*** -[__NSSetM addObject:]: object cannot be nil"; [ERROR] : line = 121; [ERROR] : message = "*** -[__NSSetM addObject:]: object cannot be nil"; [ERROR] : name = NSInvalidArgumentException; [ERROR] : nativeStack = "1 libobjc.A.dylib 0x0000000107be3735 objc_exception_throw + 48\n2 CoreFoundation 0x0000000108d344ec _CFThrowFormattedException + 194\n3 CoreFoundation 0x0000000108d58191 -[__NSSetM addObject:] + 801\n4 CoreFoundation 0x0000000108def03c __invoking___ + 140\n5 CoreFoundation 0x0000000108dec4d5 -[NSInvocation invoke] + 325\n6 mcx alexa 0x0000000101f2b5ae +[HyperloopUtils invokeSelector:args:target:instance:] + 1550\n7 mcx alexa 0x0000000101f20261 Dispatch + 1489\n8 JavaScriptCore 0x00000001023d6b9f _ZN3JSC19APICallbackFunction4callINS_18JSCallbackFunctionEEExPNS_9ExecStateE + 495\n9 ??? 0x00002e668ce0102d 0x0 + 51017985036333\n10 JavaScriptCore 0x00000001023ab33d llint_entry + 26817\n11 JavaScriptCore 0x00000001023ab33d llint_entry + 26817\n12 JavaScriptCore 0x00000001023ab33d llint_entry + 26817\n13 JavaScriptCore 0x00000001023a48fe vmEntryToJavaScript + 244\n14 JavaScriptCore 0x000000010289f36a _ZN3JSC11Interpreter14executeProgramERKNS_10SourceCodeEPNS_9ExecStateEPNS_8JSObjectE + 11178\n15 JavaScriptCore 0x0000000102acaa20 _ZN3JSC8evaluateEPNS_9ExecStateERKNS_10SourceCodeENS_7JSValueERN3WTF8NakedPtrINS_9ExceptionEEE + 288\n16 JavaScriptCore 0x00000001023d5ff5 JSEvaluateScript + 501\n17 mcx alexa 0x0000000101c0ac22 -[KrollBridge evalFileOnThread:context:] + 1314\n18 mcx alexa 0x0000000101c10b7c -[KrollInvocation invoke:] + 124\n19 mcx alexa 0x0000000101c121e3 -[KrollContext invoke:] + 163\n20 mcx alexa 0x0000000101c125a9 -[KrollContext invokeOnThread:method:withObject:callback:selector:] + 169\n21 mcx alexa 0x0000000101c0ada4 -[KrollBridge evalFile:callback:selector:] + 116\n22 mcx alexa 0x0000000101c0bc38 -[KrollBridge didStartNewContext:] + 2600\n23 mcx alexa 0x0000000101c12e9a -[KrollContext main] + 1834\n24 mcx alexa 0x0000000101c11fb7 __21-[KrollContext start]_block_invoke + 39\n25 libdispatch.dylib 0x000000010a2fc4e1 _dispatch_call_block_and_release + 12\n26 libdispatch.dylib 0x000000010a2fd54b _dispatch_client_callout + 8\n27 libdispatch.dylib 0x000000010a309380 _dispatch_main_queue_callback_4CF + 1290\n28 CoreFoundation 0x0000000108d4d3e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9\n29 CoreFoundation 0x0000000108d47a76 __CFRunLoopRun + 2342\n30 CoreFoundation 0x0000000108d46e11 CFRunLoopRunSpecific + 625\n31 GraphicsServices 0x000000010cf6b1dd GSEventRunModal + 62\n32 UIKitCore 0x000000011469881d UIApplicationMain + 140\n33 mcx alexa 0x0000000101bf7316 main + 102\n34 libdyld.dylib 0x000000010a36d575 start + 1\n35 ??? 0x0000000000000001 0x0 + 1"; [ERROR] : sourceURL = "file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/68251458-80CB-4767-B2E4-8E1D31B04D8F/mcx%20alexa.app/hyperloop/foundation/nsmutableset.js"; [ERROR] : stack = " at dispatch@[native code]\n at value@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/68251458-80CB-4767-B2E4-8E1D31B04D8F/mcx%20alexa.app/hyperloop/foundation/nsmutableset.js:121:26)\n at start@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/68251458-80CB-4767-B2E4-8E1D31B04D8F/mcx%20alexa.app/ui/common/app_ui_healthkit.js:36:25)\n at global code@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/68251458-80CB-4767-B2E4-8E1D31B04D8F/mcx%20alexa.app/app.js:35:20)"; [ERROR] : }
  11. Jan Vennemann 2018-11-01

    See my edit in my comment above. This line
        const HKQuantityTypeIdentifierBodyMassIndex = require('HealthKit/HKQuantityType');
        
    should be this
        const HKQuantityTypeIdentifierBodyMassIndex = require('HealthKit').HKQuantityTypeIdentifierBodyMassIndex;
        
    Please also see the [hyperloop-examples](https://github.com/appcelerator/hyperloop-examples) how to properly require types from native frameworks.
  12. Joachim Mollin 2018-11-01

    yes, I changed it already to const HKObjectType = require('HealthKit/HKObjectType'); const HKQuantityTypeIdentifierBodyMassIndex = require('HealthKit').HKQuantityTypeIdentifierBodyMassIndex; const NSMutableSet = require('Foundation/NSMutableSet'); const typesToWrite = new NSMutableSet(); // short for NSMutableSet.alloc().init() typesToWrite.addObject(HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex)); epr.fct.iDebug(typesToWrite); var completition = function (finished){}; var auth = epr.healthkit.healthStore.requestAuthorizationToShareTypesReadTypesCompletion(typesToWrite, typesToWrite, completition); epr.fct.iDebug(auth); my debug values are: [ Means typesToWrite are set, but auth returns null
  13. Jan Vennemann 2018-11-01

    That's because the function does return void, see https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorizationtosharetypes?language=objc Use the completion callback and check the success parameter.
  14. Jan Vennemann 2018-11-01

    PR: https://github.com/appcelerator/hyperloop.next/pull/309
  15. Joachim Mollin 2018-11-02

    sorry, but get a 404 with this link
  16. Jan Vennemann 2018-11-02

    You can't view the PR because the Hyperloop source repo is private. However you can get the latest 3.2.0 beta build that includes the fix for this issue here: https://github.com/appcelerator-modules/hyperloop-builds/releases/tag/v3.2.0-beta.2
  17. Joachim Mollin 2018-11-02

    Hallo Jan, Thanks for your help and patient. The connection to HealthKit is working. Hope I didn't nee more help. Joachim
  18. Joachim Mollin 2018-11-04

    Hi, I can write Sample to Apple HealthKit but problems to read them back. Everything ist accepted until I want to execute the query. Hope you can help. I tried building the query with 3 different methods: Version 1 -> App starts but closed immediately. No error occurred Version 3 -> the same. All debugs were shown For version 2 I got: -[HKQuantityType activateWithClientQueue:healthStore:delegate:completion:]: unrecognized selector sent to instance 0x600000d6bd40 [ERROR] : Script Error { [ERROR] : column = 26; [ERROR] : description = "-[HKQuantityType activateWithClientQueue:healthStore:delegate:completion:]: unrecognized selector sent to instance 0x600000d6bd40"; [ERROR] : line = 133; [ERROR] : message = "-[HKQuantityType activateWithClientQueue:healthStore:delegate:completion:]: unrecognized selector sent to instance 0x600000d6bd40"; [ERROR] : name = NSInvalidArgumentException; [ERROR] : nativeStack = "1 libobjc.A.dylib 0x000000010c390735 objc_exception_throw + 48\n2 CoreFoundation 0x000000010d5a4f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132\n3 CoreFoundation 0x000000010d58aed6 ___forwarding___ + 1446\n4 CoreFoundation 0x000000010d58cda8 _CF_forwarding_prep_0 + 120\n5 HealthKit 0x000000010c007263 -[HKHealthStore executeQuery:activationHandler:] + 315\n6 CoreFoundation 0x000000010d58d03c __invoking___ + 140\n7 CoreFoundation 0x000000010d58a4d5 -[NSInvocation invoke] + 325\n8 mcx alexa 0x00000001065d948e +[HyperloopUtils invokeSelector:args:target:instance:] + 1550\n9 mcx alexa 0x00000001065ce141 Dispatch + 1489\n10 JavaScriptCore 0x0000000106a85b9f _ZN3JSC19APICallbackFunction4callINS_18JSCallbackFunctionEEExPNS_9ExecStateE + 495\n11 ??? 0x00003d75e6e0102d 0x0 + 67576593911853\n12 JavaScriptCore 0x0000000106a5a33d llint_entry + 26817\n13 JavaScriptCore 0x0000000106a5a33d llint_entry + 26817\n14 JavaScriptCore 0x0000000106a5a33d llint_entry + 26817\n15 JavaScriptCore 0x0000000106a538fe vmEntryToJavaScript + 244\n16 JavaScriptCore 0x0000000106f4e36a _ZN3JSC11Interpreter14executeProgramERKNS_10SourceCodeEPNS_9ExecStateEPNS_8JSObjectE + 11178\n17 JavaScriptCore 0x0000000107179a20 _ZN3JSC8evaluateEPNS_9ExecStateERKNS_10SourceCodeENS_7JSValueERN3WTF8NakedPtrINS_9ExceptionEEE + 288\n18 JavaScriptCore 0x0000000106a84ff5 JSEvaluateScript + 501\n19 mcx alexa 0x00000001062b8492 -[KrollBridge evalFileOnThread:context:] + 1314\n20 mcx alexa 0x00000001062be3ec -[KrollInvocation invoke:] + 124\n21 mcx alexa 0x00000001062bfa53 -[KrollContext invoke:] + 163\n22 mcx alexa 0x00000001062bfe19 -[KrollContext invokeOnThread:method:withObject:callback:selector:] + 169\n23 mcx alexa 0x00000001062b8614 -[KrollBridge evalFile:callback:selector:] + 116\n24 mcx alexa 0x00000001062b94a8 -[KrollBridge didStartNewContext:] + 2600\n25 mcx alexa 0x00000001062c070a -[KrollContext main] + 1834\n26 mcx alexa 0x00000001062bf827 __21-[KrollContext start]_block_invoke + 39\n27 libdispatch.dylib 0x000000010ea904e1 _dispatch_call_block_and_release + 12\n28 libdispatch.dylib 0x000000010ea9154b _dispatch_client_callout + 8\n29 libdispatch.dylib 0x000000010ea9d380 _dispatch_main_queue_callback_4CF + 1290\n30 CoreFoundation 0x000000010d4eb3e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9\n31 CoreFoundation 0x000000010d4e5a76 __CFRunLoopRun + 2342\n32 CoreFoundation 0x000000010d4e4e11 CFRunLoopRunSpecific + 625\n33 GraphicsServices 0x00000001128d51dd GSEventRunModal + 62\n34 UIKitCore 0x0000000118d4581d UIApplicationMain + 140\n35 mcx alexa 0x00000001062a4b86 main + 102\n36 libdyld.dylib 0x000000010eb01575 start + 1\n37 ??? 0x0000000000000001 0x0 + 1"; [ERROR] : sourceURL = "file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E27FAF59-4BF6-462E-9BC9-9C3C390FC2A1/mcx%20alexa.app/hyperloop/healthkit/hkhealthstore.js"; [ERROR] : stack = " at dispatch@[native code]\n at value@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E27FAF59-4BF6-462E-9BC9-9C3C390FC2A1/mcx%20alexa.app/hyperloop/healthkit/hkhealthstore.js:133:26)\n at readParameterItem@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E27FAF59-4BF6-462E-9BC9-9C3C390FC2A1/mcx%20alexa.app/ui/common/app_ui_healthkit.js:241:47)\n at global code@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E27FAF59-4BF6-462E-9BC9-9C3C390FC2A1/mcx%20alexa.app/app.js:231:29)"; [ERROR] : } Code: //sampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryEnergyConsumed) var HKSampleType = require('HealthKit/HKSampleType'); var sampleType = HKSampleType.quantityTypeForIdentifier(require('HealthKit').HKQuantityTypeIdentifierBodyMass); epr.fct.iDebug(HKSampleType); epr.fct.iDebug(sampleType); epr.fct.iDebug("END SAMPLETYPE"); //let predicate = HKQuery.predicateForSamplesWithStartDate(startDate, endDate: endDate, options: .None) var HKQuery = require('HealthKit/HKQuery'); var predicate = HKQuery.predicateForSamplesWithStartDateEndDateOptions(startDate, endDate, null); epr.fct.iDebug(predicate); epr.fct.iDebug("END PREDICAT"); //Sort //NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO]; var HKSort = require('Foundation/NSSortDescriptor'); var sortDesc = new HKSort(require('HealthKit').HKSampleSortIdentifierEndDate,true); epr.fct.iDebug(sortDesc); epr.fct.iDebug("END SORT"); //init(sampleType: HKSampleType,predicate: NSPredicate?,limit: Int,sortDescriptors: [NSSortDescriptor]?,resultsHandler: @escaping (HKSampleQuery, [HKSample]?, Error?) -> Void) var HKSampleQuery = require('HealthKit/HKSampleQuery'); epr.fct.iDebug(HKSampleQuery); //version 1 var query = HKSampleQuery.alloc().init(sampleType, predicate, require('HealthKit').HKObjectQueryNoLimit, sortDesc, fctResult); //version 2 //var query = new HKSampleQuery(sampleType, predicate, require('HealthKit').HKObjectQueryNoLimit, sortDesc, fctResult); //version 3 /*q = new HKSampleQuery(); q.sampleType = sampleType; q.predicate = predicate; q.limit = require('HealthKit').HKObjectQueryNoLimit; q.sortDescriptors = sortDesc; q.resultsHandler = fctResult; epr.fct.iDebug(q); query = q;*/ epr.fct.iDebug(query); epr.fct.iDebug("END query"); var ok = epr.hk.healthStore.executeQuery(query); epr.fct.iDebug("END EXECUTE");
  19. Joachim Mollin 2018-11-04

    This error is shown in the Simulator /hkhealthstore.js:133 var result = $dispatch(this.$native, 'executeQuery:', [_query], true); ^ -[HKQuantityType activateWithClientQueue:healthStore:delegate:completion:]: unrecognized selector sent to instance 0x6000031760d0 at dispatch@[native code] at value@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/13AC1432-F4BC-4508-A72F-1FAC5A7CE127/mcx%20alexa.app/hyperloop/healthkit/hkhealthstore.js:133:26) at readParameterItem@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/13AC1432-F4BC-4508-A72F-1FAC5A7CE127/mcx%20alexa.app/ui/common/app_ui_healthkit.js:241:47) at global code@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/13AC1432-F4BC-4508-A72F-1FAC5A7CE127/mcx%20alexa.app/app.js:231:29) 4 mcx alexa 0x000000010c9b13ec -[KrollInvocation invoke:] + 124 5 mcx alexa 0x000000010c9b2a53 -[KrollContext invoke:] + 163 6 mcx alexa 0x000000010c9b2e19 -[KrollContext invokeOnThread:method:withObject:callback:selector:] + 169 7 mcx alexa 0x000000010c9ab614 -[KrollBridge evalFile:callback:selector:] + 116 8 mcx alexa 0x000000010c9ac4a8 -[KrollBridge didStartNewContext:] + 2600 9 mcx alexa 0x000000010c9b370a -[KrollContext main] + 1834 10 mcx alexa 0x000000010c9b2827 __21-[KrollContext start]_block_invoke + 39 11 libdispatch.dylib 0x000000011509e4e1 _dispatch_call_block_and_release + 12 12 libdispatch.dylib 0x000000011509f54b _dispatch_client_callout + 8 13 libdispatch.dylib 0x00000001150ab380 _dispatch_main_queue_callback_4CF + 1290 14 CoreFoundation 0x0000000113aef3e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 15 CoreFoundation 0x0000000113ae9a76 __CFRunLoopRun + 2342 16 CoreFoundation 0x0000000113ae8e11 CFRunLoopRunSpecific + 625 17 GraphicsServices0x0000000118ee31dd GSEventRunModal + 62 18 UIKitCore 0x000000011f43d81d UIApplicationMain + 140 19 mcx alexa 0x000000010c997b86 main + 102
  20. Jan Vennemann 2018-11-05

    Again, you need to use the correct native functions! You use HKSampleQuery.alloc().init( or new HKSampleQuery(), but that is the default initializer provided by NSobject. Check the docs at https://developer.apple.com/documentation/healthkit/hksamplequery?language=objc and use the appropriate initializer.
  21. Joachim Mollin 2018-11-05

    Sorry Jan, of course I'm not a object-c developer and maybe I'm stupid or blind but I follow exactly the example from Apple HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:predicate limit:HKObjectQueryNoLimit sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {.... or the example of old Ti.HealthKit module HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType: [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount] predicate: predicate limit: limit sortDescriptors: @[endDateSort] resultsHandler:^(HKSampleQuery *query, NSArray* results, NSError *error){ NSLog(@"SHAPERACE LOG: getSteps method with error = %@", error); [self sendStepsData: results]; if (completionHandler) completionHandler(); }]; means using the class HKSampleQuery and initialize with the prepared items So what's the appropriate initializer var query = new HKSampleQuery(sampleType, predicate, require('HealthKit').HKObjectQueryNoLimit, sortDesc, fctResult);
  22. Jan Vennemann 2018-11-05

    See the [Named Methods](https://docs.appcelerator.com/platform/latest/#!/guide/iOS_Hyperloop_Programming_Guide-section-src-46253491_iOSHyperloopProgrammingGuide-Namedmethods) section in the [Hyperloop iOS Guide](https://docs.appcelerator.com/platform/latest/#!/guide/iOS_Hyperloop_Programming_Guide). Every named parameter in Objective-C becomes part of the method name in JavaScript. Hyperloop will remove the colons, capitalize the first letter of every parameter name and form the final method name from that. In your case initWithSampleType:predicate:limit:sortDescriptors:resultsHandler: becomes initWithSampleTypePredicateLimitSortDescriptorsResultsHandler(sampleType, predicate, HKObjectQueryNoLimit, sortDesc, fctResult)
  23. Joachim Mollin 2018-11-05

    you are right, I understood that constructions but initWithSampleTypePredicateLimitSortDescriptorsResultsHandler is not a function/method in any class
  24. Jan Vennemann 2018-11-05

    Have you tried HKSampleQuery.alloc().initWithSampleTypePredicateLimitSortDescriptorsResultsHandler(sampleType, predicate, HKObjectQueryNoLimit, sortDesc, callback); ?
  25. Joachim Mollin 2018-11-05

    yes, I have tried this besides many other things. With your example I get the message, that .alloc().initWithSampleTypePredicateLimitSortDescriptorsResultsHandler is not a function [ERROR] : Script Error { [ERROR] : column = 97; [ERROR] : line = 226; [ERROR] : message = "HKSampleQuery.alloc().initWithSampleTypePredicateLimitSortDescriptorsResultHandler is not a function. (In 'HKSampleQuery.alloc().initWithSampleTypePredicateLimitSortDescriptorsResultHandler(sampleType, predicate, require(\"/hyperloop/healthkit/healthkit\").HKObjectQueryNoLimit, sortDesc, fctResult)', 'HKSampleQuery.alloc().initWithSampleTypePredicateLimitSortDescriptorsResultHandler' is undefined)"; [ERROR] : sourceURL = "file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E4FB6019-9B3C-4B2E-BDDC-ED87918D806A/mcx%20alexa.app/ui/common/app_ui_healthkit.js"; [ERROR] : stack = " at readParameterItem@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E4FB6019-9B3C-4B2E-BDDC-ED87918D806A/mcx%20alexa.app/ui/common/app_ui_healthkit.js:226:97)\n at global code@file:///Users/mollin/Library/Developer/CoreSimulator/Devices/80119195-156D-4879-8609-9CE5FDD6FF33/data/Containers/Bundle/Application/E4FB6019-9B3C-4B2E-BDDC-ED87918D806A/mcx%20alexa.app/app.js:231:29)"; [ERROR] : }
  26. Jan Vennemann 2018-11-05

    Check the spelling, you are missing an "s" in ...Result{color:red}s{color}Handler
  27. Joachim Mollin 2018-11-05

    shit. I didn't checked that. Sorry. Now get a result. Not what I expected but an error as result. var fctResult = function (query, sample, error){ epr.fct.iDebug("GET BACK with read"); epr.fct.iDebug(query); epr.fct.iDebug(sample); epr.fct.iDebug(error); epr.fct.iDebug ('*****************************'); }; gives [INFO] : GET BACK with read [INFO] : [INFO] : [INFO] : Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.healthd.server was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service named com.apple.healthd.server was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.} [INFO] : ***************************** [INFO] : 1 What ever it means
  28. Joachim Mollin 2018-11-07

    ok. now works error was produced by var HKSort = require('Foundation/NSSortDescriptor'); var sortDesc = new HKSort(require('HealthKit').HKSampleSortIdentifierEndDate,true); setting sortDesc = null gives back an object in variable sample. This should be an array following apple HealthKit documentation in TI its a KrollBack object. How to convert to a JS structure?
  29. Joachim Mollin 2018-11-07

    I tried to cast as a NSObject var fctResult = function (query, sampleObj, error){ epr.fct.iDebug("GET BACK with read"); epr.fct.iDebug(query); epr.fct.iDebug(sampleObj); epr.fct.iDebug(error); epr.fct.iDebug ('*****************************'); epr.fct.iDebug (typeof sampleOrg); var sample = require('Foundation/NSArray').cast(sampleObj); but no change
  30. Jan Vennemann 2018-11-07

    [~mollin], please use proper code formatting, your posts are very hard to follow. So what's the output of your code? What's the issue with sampleObj? Can't you call sampleObj.objectAtIndex(0) on it, for example?
  31. Joachim Mollin 2018-11-08

    Jan, yes, I can access the object and can extract the 1st part, which itself is an object. epr.fct.iDebug(sampleObj); epr.fct.iDebug (typeof sampleObj+" SampleObj"); gives the result ( "80 kg 641BEE94-6B6E-4B70-B8B7-A0DA4D3BC5DE \"mcx alexa\" (1.3), \"iPhone9,1\" (12.1) (2018-11-02 18:52:00 +0100 - 2018-11-02 18:52:00 +0100)", "80 kg CB6080A5-0AE7-4B30-B044-7CE5D8D4079F \"mcx alexa\" (1.3), \"iPhone9,1\" (12.1) (2018-11-02 18:54:24 +0100 - 2018-11-02 18:54:24 +0100)", "80 kg C9F9DBE6-6A95-45F2-8239-6AB25D5A3268 \"mcx alexa\" (1.3), \"iPhone9,1\" (12.1) (2018-11-02 18:55:34 +0100 - 2018-11-02 18:55:34 +0100)", "78 kg 1CD18E7C-E770-4DB9-A0E3-6E4F99330136 \"mcx alexa\" (1.3), \"iPhone9,1\" (12.1) (2018-11-02 19:07:56 +0100 - 2018-11-02 19:07:56 +0100)" ) object SampleObj var sample = sampleObj.objectAtIndex(0); epr.fct.iDebug(typeof sample+" - Sample"); epr.fct.iDebug(sample); epr.fct.iDebug(sample.toString); gives the result object - Sample 80 kg 641BEE94-6B6E-4B70-B8B7-A0DA4D3BC5DE "mcx alexa" (1.3), "iPhone9,1" (12.1) (2018-11-02 18:52:00 +0100 - 2018-11-02 18:52:00 +0100) var part = sample.objectAtIndex(0); gives then the error JS exception encountered calling callback: sample.objectAtIndex is not a function. (In 'sample.objectAtIndex(0)', 'sample.objectAtIndex' is undefined) I also tried to iterate with for (x in sample) through the object. But there is no chance to extract the other parts of the object. apple says in documentation that sampleObj should be an array, I guess an NSArray. Can I cast it, as I already tried with no success. regards Joachim
  32. Joachim Mollin 2018-11-08

    sorry for the format. I tried to work with tab indents, but after sending they are gone
  33. Jan Vennemann 2018-11-08

    What makes you think the first object you get from the array is also a NSArray? According to the docs it is of type [HKSample](https://developer.apple.com/documentation/healthkit/hksample?language=objc) and you should be able to access it via const sample = HKQuantitySample.cast(sampleObj.objectAtIndex(0)). This may vary depending on the sample type you queried. You can use a simple for-loop to iterate over all objects in the sampleObj array. Please read the docs more carefully. All your errors have been because of spelling errors or the use of wrong types. If you require further assistance please resort to the community slack as this is getting way of scope of this ticket.
  34. Joachim Mollin 2018-11-08

    Dear Jan, its maybe more a problem that casting of objects isn't described very well. just 4 or 5 lines of text. If I get you right. I have an object of type HKQuantitySample in my variable. Means an object with different properties. One property is, regarding to apple, HKQuantity defined in 'Healthkit/HKQuantity', which I define like this: var HKQuantity = require('HealthKit/HKQuantity'); I do the same when creating the object for writing. So I should be able to access the property value with var wq = sample.HKQuantity? unfortunately the result is null instead of 80
  35. Joachim Mollin 2018-11-08

    Just for your info! it is very interesting, that its not a single cast object hyperloop gives back var HKQuantitySample = require('HealthKit/HKQuantitySample'); var HKObject = require('HealthKit/HKObject'); var sample = HKObject.cast(sampleObj.objectAtIndex(0)); var sample1 = HKQuantitySample.cast(sampleObj.objectAtIndex(0)); epr.fct.iDebug(sample.UUID); //gives a result epr.fct.iDebug(sample.MetaData); //gives null epr.fct.iDebug(sample.Device); //gives null epr.fct.iDebug(sample1.enddate); //gives null epr.fct.iDebug(sample1.startdate); //gives null epr.fct.iDebug(sample1.quantity); // gives a result 80 kg as stored You cannot found those info in the documentation. its just try and error
  36. Joachim Mollin 2018-11-08

    got now everything without startDate and endDate. Any Idea?
  37. Jan Vennemann 2018-11-08

    Try start{color:red}D{color}ate and end{color:red}D{color}ate, with a capital D, see here: https://developer.apple.com/documentation/healthkit/hksample/1615481-startdate?language=objc
  38. Joachim Mollin 2018-11-08

    I did as well. no chance. no success

JSON Source