-1

I want to access my healthKit data in a locally stored .html file (loaded in UIWebView).
My goal is to plot the heart rate, body temperature, calories etc with D3.js in the html file.

(My D3.js plots are already created and works fine in webView accessing hardcoded data from locally stored .csv file)

I have been granted permissions from the HealthStore and know how to query for the data using swift.

Below is a query output (array) from the console in in Xcode, showing my heart rate on different days.

How can I access this HealthKit data in a local html file, in a format readable for D3?

Console Output:

[0.916667 count/s "Health" metadata: { HKWasUserEntered = 1; } 2014-11-30 13:02:00 +0100 2014-11-30 13:02:00 +0100, 1.03333 count/s "Health" metadata: { HKWasUserEntered = 1; } 2014-11-28 13:03:00 +0100 2014-11-28 13:03:00 +0100, 0.95 count/s "Health" metadata: { HKWasUserEntered = 1; } 2014-11-26 13:03:00 +0100 2014-11-26 13:03:00 +0100]

KML
  • 2,302
  • 5
  • 26
  • 47

2 Answers2

0

You need to use the Javascript Bridge to send the messages from iOS to WebView and vice-versa.

It can be achieved using the following library: WebViewJavascript Bridge

Or else you can use the PhoneGap Cleaver Configuration to use the PhoneGap WebView. This will allow you to communicate with the native controls.

Akhilesh Sharma
  • 1,580
  • 1
  • 17
  • 29
  • Are not both of these options based on Objective C ? – KML Dec 01 '14 at 16:36
  • Swift is pretty much compatible with objective-c. You can use that along with it. – Akhilesh Sharma Dec 01 '14 at 16:40
  • what about WKWebview, does that make it possible, or does it also require a separate bridge? http://stackoverflow.com/questions/25827368/swift-webview-how-to-call-correctly-swift-code-from-javascript – KML Dec 01 '14 at 16:41
  • Yes you can use WKWebView as its the part of the native API. I have not used that as such in past, have tried these two approaches and worked magnificently. – Akhilesh Sharma Dec 01 '14 at 16:45
0

Why not use WKWebView? Since you are using HealthKit, that means iOS 8 is required. Besides performance boost, WKWebView provides decent API for passing message from JS to native. If you need high level binding API, please check the XWebView project.

soflare
  • 751
  • 5
  • 16