Best Fitness Plugins for Ionic 4 - How to use Pedometer
Tags: ionic, pedometer, googlefit, healthkit
Published: 2019-09-16 13:12:43

<main role="main"><article class=" u-minHeight100vhOffset65 u-overflowHidden postArticle postArticle--full is-withAccentColors" lang="en"><div class="postArticle-content js-postField js-notesSource editable" id="editor_6" g_editable="true" role="textbox" contenteditable="true" data-default-value="Title
Tell your story…" spellcheck="false"><section name="30b0" class="section section--body section--first"><div class="section-divider"><hr class="section-divider"></div><div class="section-content"><div class="section-inner sectionLayout--insetColumn"><p name="4342" class="graf graf--p graf-after--figure">Today more and more people are opting to cut the gym out completely and get fit where and when it suits them&#8202;—&#8202;from the comfort of their devices. There are rising number of apps out there that complement your workout schedule as well as keep your data history to analyze your health over time.</p><p name="88c4" class="graf graf--p graf-after--p">Given jam-packed schedules, it is getting tougher for an individual to think about health on top of everything else. It might seem like a full-time job. Luckily, we are living in the 21st century, and technology is here to help. So this is high time to launch apps in the health and fitness domain.</p><figure tabindex="0" contenteditable="false" name="e0bd" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 480px; max-height: 480px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 100%;"></div><img class="graf-image" data-image-id="1*yvVfl6Pms7pUd2ejGS-KzQ.jpeg" data-width="480" data-height="480" src="https://cdn-images-1.medium.com/max/720/1*yvVfl6Pms7pUd2ejGS-KzQ.jpeg"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Don’t be that&nbsp;minion</figcaption></figure><p name="f3bd" class="graf graf--p graf-after--figure">All the relevant and necessary health data of user is available over both the platforms, Android as well as iOS. You can add value by processing that data and chipping in your novel ideas, algorithm, logic and thus providing new useful insights.</p><blockquote name="6d3a" class="graf graf--blockquote graf-after--p">Because health data may contain sensitive, personal information, apps must receive permission from the user to read and modify data. They must also take steps to protect that data at all times.</blockquote><p name="266b" class="graf graf--p graf-after--blockquote">In this post we will learn about the default Health app options Google and Apple provide within their devices, and how can you connect your <strong class="markup--strong markup--p-strong">Ionic 4 apps</strong> to make use of these data.</p><h3 name="1167" class="graf graf--h3 graf-after--p">Default Fitness&nbsp;Packages</h3><h4 name="227f" class="graf graf--h4 graf-after--h3">HealthKit, iOS</h4><p name="8851" class="graf graf--p graf-after--h4">HealthKit on iPhone provides a central repository for health and fitness data on iPhone and Apple Watch. With the user’s permission, apps can communicate with the HealthKit store to access and share this data.</p><figure tabindex="0" contenteditable="false" name="d2b6" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 394px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 56.39999999999999%;"></div><img class="graf-image" data-image-id="1*TsnPAMnKKdsrRM80H2bgcw.jpeg" data-width="1180" data-height="665" src="https://cdn-images-1.medium.com/max/720/1*TsnPAMnKKdsrRM80H2bgcw.jpeg"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">iOS HealthKit gives a complete bundle of health related&nbsp;data</figcaption></figure><p name="942c" class="graf graf--p graf-after--figure">Creating a complete, personalized health and fitness experience includes a variety of tasks:</p><ul class="postList"><li name="80ab" class="graf graf--li graf-after--p">Collecting and storing health and fitness data</li><li name="75a2" class="graf graf--li graf-after--li">Analyzing and visualizing the data</li><li name="65e3" class="graf graf--li graf-after--li">Enabling social interactions</li></ul><p name="9f57" class="graf graf--p graf-after--li">The main dashboard for Apple Health is called Health Data and breaks down your health into four key areas: Activity, Mindfulness, Nutrition and Sleep.</p><figure tabindex="0" contenteditable="false" name="ecfd" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 467px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 66.8%;"></div><img class="graf-image" data-image-id="1*GSgQ-KLnrskZKfCfFgxCLw.png" data-width="1880" data-height="1255" src="https://cdn-images-1.medium.com/max/720/1*GSgQ-KLnrskZKfCfFgxCLw.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">iOS Healthkit features</figcaption></figure><p name="51de" class="graf graf--p graf-after--figure is-selected">HealthKit apps take a collaborative approach to building this experience. HealthKit app allows data exchange with other apps. Your app does not need to provide all of the features of HealthKit. Instead, you can focus just on the subset of tasks that most interests you.</p><p name="ab67" class="graf graf--p graf-after--p">For example, users can select their favorite weight-tracking, step-counting, and health challenge app, each calibrated to their personal needs. Because HealthKit apps freely exchange data (with user permission), the combined suite provides a more customized experience than any single app on its own. For example, when a group of friends joins a daily step-counting challenge, each person can use their preferred hardware device and app to track their steps, while everyone in the group uses the same social app for the challenge.</p><figure tabindex="0" contenteditable="false" name="e3fc" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 500px; max-height: 375px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 75%;"></div><img class="graf-image" data-image-id="1*RD_QUHgqRnIa5ersltYRXg.png" data-width="500" data-height="375" src="https://cdn-images-1.medium.com/max/720/1*RD_QUHgqRnIa5ersltYRXg.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Ugh&nbsp;… that&nbsp;s**ks</figcaption></figure><p name="5275" class="graf graf--p graf-after--figure">HealthKit is also designed to manage and merge data from multiple sources. For example, users can view and manage all of their data in the Health App, including adding data, deleting data, and changing an app’s permissions. Therefore, your app needs to handle these changes, even when they occur outside your app.</p><h4 name="48b4" class="graf graf--h4 graf-after--p">Google Fit,&nbsp;Google</h4><figure tabindex="0" contenteditable="false" name="7aa5" class="graf graf--figure graf-after--h4"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 469px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 66.9%;"></div><img class="graf-image" data-image-id="1*T9GEIastweEQLLKnFSBaLA.jpeg" data-width="1600" data-height="1071" src="https://cdn-images-1.medium.com/max/720/1*T9GEIastweEQLLKnFSBaLA.jpeg"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Google Fit is similar to iOS HealthKit</figcaption></figure><p name="ae71" class="graf graf--p graf-after--figure">Google Fit is a health-tracking platform developed by Google for the Android operating system. It is a single set of APIs that blends data from multiple apps and devices. Google Fit uses sensors in a user’s activity tracker or mobile device to record physical fitness activities (such as walking or cycling), which are measured against the user’s fitness goals to provide a comprehensive view of their fitness. It lets</p><ul class="postList"><li name="3c83" class="graf graf--li graf-after--p">Users control their fitness data</li><li name="82f6" class="graf graf--li graf-after--li">Developers build smarter apps, and</li><li name="814e" class="graf graf--li graf-after--li">Manufacturers focus on creating amazing devices.</li></ul><p name="9921" class="graf graf--p graf-after--li">Google Fit allows developers to upload fitness data to a central repository where users can access their data from different devices and apps in one location:</p><ul class="postList"><li name="1d3d" class="graf graf--li graf-after--p">Fitness apps can store data from any wearable or sensor.</li><li name="d3d1" class="graf graf--li graf-after--li">Fitness apps can access data created by other apps.</li><li name="b7cb" class="graf graf--li graf-after--li">User’s fitness data is persisted when they upgrade their fitness devices.</li></ul><figure tabindex="0" contenteditable="false" name="bd9f" class="graf graf--figure graf-after--li"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 394px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 56.3%;"></div><img class="graf-image" data-image-id="1*9uplFadrlSiM-04gGPBkMA.jpeg" data-width="1200" data-height="675" src="https://cdn-images-1.medium.com/max/720/1*9uplFadrlSiM-04gGPBkMA.jpeg"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Google Fit syncs across&nbsp;devices</figcaption></figure><p name="104e" class="graf graf--p graf-after--figure">Since you read fitness data from Google Fit, you are also required to write the fitness data you collect to Google Fit.</p><p name="dcdb" class="graf graf--p graf-after--p">Google Fit APIs are prohibited for non-fitness purposes, such as storing medical or biometric data, selling data, or using data for advertising.</p><h3 name="078e" class="graf graf--h3 graf-after--p">Fitness plugins in Ionic&nbsp;4</h3><p name="c6fa" class="graf graf--p graf-after--h3">Now let’s see how we can use the Fitness data in Ionic 4 apps</p><h4 name="1701" class="graf graf--h4 graf-after--p">1. Health KitPlugin</h4><p name="35b7" class="graf graf--p graf-after--h4">The HealthKit plugin allows you to read data from and write data to the iOS 8+ HealthKit framework. Any data saved shows up in the iOS Health app, and is available for other iOS apps.</p><h4 name="a292" class="graf graf--h4 graf-after--p">2. Health</h4><p name="0004" class="graf graf--p graf-after--h4">A plugin that abstracts fitness and health repositories like Apple HealthKit or Google Fit. This is the most extensive plugin among all available ones.</p><h4 name="e997" class="graf graf--h4 graf-after--p">3. Pedometer</h4><p name="f369" class="graf graf--p graf-after--h4">Fetch pedestrian-related pedometer data, such as step counts and other information about the distance traveled.</p><h4 name="a766" class="graf graf--h4 graf-after--p">4. Stepcounter</h4><p name="05a7" class="graf graf--p graf-after--h4">Cordova plugin for using device’s stepcounter on Android (API &gt; 19)</p><p name="8add" class="graf graf--p graf-after--p">We’ll go in details of the <strong class="markup--strong markup--p-strong">Health Plugin</strong>, which is most extensive among all these plugins. All other plugins will behave in a similar way.</p><h3 name="13db" class="graf graf--h3 graf-after--p">Ionic 4 Health&nbsp;Plugin</h3><h4 name="ed8b" class="graf graf--h4 graf-after--h3">Install Plugin</h4><p name="e4cd" class="graf graf--p graf-after--h4">To begin with, we need a basic Ionic 4 app. If you are a beginner, you can check out our blog on <a href="https://medium.com/enappd/how-to-create-an-ionic-4-app-for-beginners-e181e116190a"  class="markup--anchor markup--p-anchor"    target="_blank">How to create Ionic 4 apps</a>. Once you have a basic Ionic 4 app, import the Health plugin by</p><pre name="eff1" class="graf graf--pre graf-after--p">$ ionic cordova plugin add cordova-plugin-health<br>$ npm install @ionic-native/health</pre><h4 name="daa2" class="graf graf--h4 graf-after--pre">Import plugin in your&nbsp;page</h4><p name="f264" class="graf graf--p graf-after--h4">Import the plugin in your page/ component using</p><pre name="0d8b" class="graf graf--pre graf-after--p"><code class="markup--code markup--pre-code">import { Health } from '@ionic-native/health/ngx';</code></pre><pre name="9d78" class="graf graf--pre graf-after--pre"><code class="markup--code markup--pre-code">constructor(private health: Health) { }</code></pre><h4 name="423e" class="graf graf--h4 graf-after--pre">Include plugin in app providers</h4><p name="f252" class="graf graf--p graf-after--h4">Also import the plugin provider in <code class="markup--code markup--p-code"><strong class="markup--strong markup--p-strong">app.module.ts</strong></code> and include the plugin in providers array</p><pre name="4cd6" class="graf graf--pre graf-after--p">import { Health } from '@ionic-native/health/ngx';</pre><pre name="b12b" class="graf graf--pre graf-after--pre">@NgModule({<br>...<br>providers: [<br>...,<br>Health,<br>{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }<br>],<br>bootstrap: [AppComponent]<br>})</pre><h4 name="dd2f" class="graf graf--h4 graf-after--pre">Check platform is&nbsp;ready</h4><p name="f6b3" class="graf graf--p graf-after--h4">One important thing to note is to access the plugin only when the Platform is ready. Otherwise it will throw error of <code class="markup--code markup--p-code">plugin not installed</code> or may be it won’t throw any error but just won’t work.</p><pre name="d13c" class="graf graf--pre graf-after--p">ngOnInit() {<br>    this.checkPlatformReady();<br>}</pre><pre name="92b1" class="graf graf--pre graf-after--pre">async checkPlatformReady() {<br>    const ready = !!await this.platform.ready();<br>    if (ready) {<br>        // Use plugin functions here<br>    }<br>}</pre><h4 name="3261" class="graf graf--h4 graf-after--pre">iOS quirks</h4><p name="9a34" class="graf graf--p graf-after--h4">This is a requirement in iOS only. For any app that wants to read/write private data, the app requests permission from user along with a usage description. For our Health plugin, we need <code class="markup--code markup--p-code">read</code> and <code class="markup--code markup--p-code">write</code> permission. These can be set in <code class="markup--code markup--p-code">info.plist</code> in Xcode. Without this the app will crash in iOS when you try to run any function other than <code class="markup--code markup--p-code">isAvailable()</code></p><figure tabindex="0" contenteditable="false" name="e7db" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 405px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 57.8%;"></div><img class="graf-image" data-image-id="1*L6gSp4GfTGESL8nWVUS1Bw.png" data-width="856" data-height="495" src="https://cdn-images-1.medium.com/max/720/1*L6gSp4GfTGESL8nWVUS1Bw.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Add app’s usage description for using Apple’s Health&nbsp;Kit</figcaption></figure><p name="cb38" class="graf graf--p graf-after--figure">Also, make sure your app id has the ‘HealthKit’ entitlement when this plugin is installed. This is added automatically to your app if you use Cordova-ios 4.3.0 or higher.</p><figure tabindex="0" contenteditable="false" name="cef6" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 412px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 58.9%;"></div><img class="graf-image" data-image-id="1*eGIpS-c23FzGJJQ9-XSvZg.png" data-width="857" data-height="505" src="https://cdn-images-1.medium.com/max/720/1*eGIpS-c23FzGJJQ9-XSvZg.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Enable HealthKit entitlement for your app in&nbsp;Xcode</figcaption></figure><p name="a1b5" class="graf graf--p graf-after--figure">You need to have HealthKit entitlement in your app’s provisioning profile.</p><h3 name="e7f1" class="graf graf--h3 graf-after--p">Methods</h3><h4 name="7818" class="graf graf--h4 graf-after--h3">isAvailable()</h4><p name="df85" class="graf graf--p graf-after--h4">Tells if either Google Fit or HealthKit are available.</p><h4 name="5bb0" class="graf graf--h4 graf-after--p">promptInstallFit()</h4><p name="cbed" class="graf graf--p graf-after--h4">Checks if recent Google Play Services and Google Fit are installed. If the play services are not installed, or are obsolete, it will show a pop-up suggesting to download them.</p><h4 name="7d2a" class="graf graf--h4 graf-after--p">requestAuthorization()</h4><p name="8867" class="graf graf--p graf-after--h4">Requests read and write access to a set of data types. This method must be called before using the query and store methods, even if the authorization has already been given at some point in the past. Failure to do so may cause your app to crash, or in the case of Android, Google Fit may not be ready.</p><pre name="0a0d" class="graf graf--pre graf-after--p">this.health.requestAuthorization([<br>'distance', 'nutrition',  //read and write permissions<br> {<br>    read: ['steps','height', 'weight'],//read only permission<br>    write: ['height', 'weight']  //write only permission<br> }<br>])<br>.then(res =&gt; console.log("response " + res))<br>.catch(e =&gt; console.log("error "+e));</pre><figure tabindex="0" contenteditable="false" name="7db1" class="graf graf--figure graf-after--pre"><div class="aspectRatioPlaceholder is-locked" style="max-width: 300px; max-height: 534px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 178%;"></div><img class="graf-image" data-image-id="1*cryE85JbLU0K62D4FvgDpQ.png" data-width="300" data-height="534" src="https://cdn-images-1.medium.com/max/720/1*cryE85JbLU0K62D4FvgDpQ.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">App requesting permission from iOS Health&nbsp;Kit</figcaption></figure><h4 name="c5e1" class="graf graf--h4 graf-after--figure">query()</h4><p name="fc5a" class="graf graf--p graf-after--h4">This method gets all the data points of a certain data type within a certain time window. This is the essence of Health plugins, using this function we can read and write data from iOS Health Kit and Google Fit.</p><p name="7ba1" class="graf graf--p graf-after--p">To begin with, we have some sample data in the iOS HealthKit dataset</p><figure tabindex="0" contenteditable="false" name="c76f" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 518px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 74%;"></div><img class="graf-image" data-image-id="1*qBJmWj9Q4eYGR4OXJmb33w.png" data-width="1000" data-height="740" src="https://cdn-images-1.medium.com/max/720/1*qBJmWj9Q4eYGR4OXJmb33w.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">iOS Healthkit dataset for sample&nbsp;data</figcaption></figure><p name="503c" class="graf graf--p graf-after--figure">Sample query</p><pre name="775d" class="graf graf--pre graf-after--p">this.health.query({<br>  startDate: new Date(new Date().getTime() - 10*24*60*60*1000 ), <br>  // ten days ago<br>  endDate: new Date(), // now<br>  dataType: 'steps',<br>  limit: 1000<br>}).then(data=&gt;{<br>  console.log(data);<br>}).catch(e =&gt; {<br>  console.log("error "+ e);<br>})</pre><p name="8a40" class="graf graf--p graf-after--pre">On executing the above <code class="markup--code markup--p-code">query</code>&nbsp;, you will get a result similar to the following (Assuming you have data in HealthKit)</p><figure tabindex="0" contenteditable="false" name="cdf1" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 298px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 42.5%;"></div><img class="graf-image" data-image-id="1*dbvasgXTD3yP6At9vHC-zw.png" data-width="1000" data-height="425" src="https://cdn-images-1.medium.com/max/720/1*dbvasgXTD3yP6At9vHC-zw.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Steps data from last 10 days&#8202;—&#8202;Safari debug&nbsp;console</figcaption></figure><p name="01ff" class="graf graf--p graf-after--figure">As an example, the data from our example repo shows a 10 day data like following</p><figure tabindex="0" contenteditable="false" name="3b15" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 300px; max-height: 534px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 178%;"></div><img class="graf-image" data-image-id="1*epyK08RziFFHGpvy-kf2zQ.png" data-width="300" data-height="534" src="https://cdn-images-1.medium.com/max/720/1*epyK08RziFFHGpvy-kf2zQ.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Past 10 days steps data from iOS HealthKit</figcaption></figure><h4 name="6162" class="graf graf--h4 graf-after--figure">queryAggregated()</h4><p name="533f" class="graf graf--p graf-after--h4">Another query method, but instead of individual values, it returns a sum of values. E.g. when you want to check the steps walked in last one week etc.</p><pre name="7153" class="graf graf--pre graf-after--p">this.health.queryAggregated({<br>  startDate: new Date(new Date().getTime() - 10*24*60*60*1000 ), <br>  // ten days ago<br>  endDate: new Date(), // now<br>  dataType: 'steps',<br>  bucket: 'week'<br>}).then(data=&gt;{<br>  console.log(data);<br>}).catch(e =&gt; {<br>  console.log("error "+ e);<br>})</pre><figure tabindex="0" contenteditable="false" name="c12b" class="graf graf--figure graf-after--pre"><div class="aspectRatioPlaceholder is-locked" style="max-width: 700px; max-height: 267px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 38.1%;"></div><img class="graf-image" data-image-id="1*LrQZbRfrItLkKAov8V1dZw.png" data-width="1003" data-height="382" src="https://cdn-images-1.medium.com/max/720/1*LrQZbRfrItLkKAov8V1dZw.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">Aggregated steps data from last 10 days, week wise&#8202;—&#8202;Safari debug&nbsp;console</figcaption></figure><p name="3391" class="graf graf--p graf-after--figure">As an example, the data from our example repo shows a 10 day data, grouped in weeks, like this</p><figure tabindex="0" contenteditable="false" name="adf3" class="graf graf--figure graf-after--p"><div class="aspectRatioPlaceholder is-locked" style="max-width: 300px; max-height: 534px;"><div class="aspectRatioPlaceholder-fill" style="padding-bottom: 178%;"></div><img class="graf-image" data-image-id="1*qMjCYDpDgzeCpqDUdX5cnQ.png" data-width="300" data-height="534" src="https://cdn-images-1.medium.com/max/720/1*qMjCYDpDgzeCpqDUdX5cnQ.png"><div class="crosshair u-ignoreBlock"></div></div><br/><figcaption class="imageCaption" contenteditable="true" data-default-value="Type caption for image (optional)">10 days Steps data aggregated into&nbsp;weeks</figcaption></figure><h4 name="79d8" class="graf graf--h4 graf-after--figure">store()</h4><p name="5116" class="graf graf--p graf-after--h4">This method can be used to store data from your Ionic 4 app to HealthKit or Google Fit</p><pre name="ffe5" class="graf graf--pre graf-after--p">this.health.store({<br>  startDate: new Date(new Date().getTime() - 3*60*1000 ), <br>  // three minutes ago<br>  endDate: new Date(), // now<br>  <code class="markup--code markup--pre-code">dataType: 'steps',<br>  value: 180,<br>  sourceName: 'my_app',<br>  sourceBundleId: 'com.example.my_app'</code><br>}).then(data=&gt;{<br>  console.log(data);<br>}).catch(e =&gt; {<br>  console.log("error "+ e);<br>})</pre><p name="a0a9" class="graf graf--p graf-after--pre">More details related to the data types, methods and quirks for the Health plugin are available on the <a href="https://github.com/dariosalvi78/cordova-plugin-health"  class="markup--anchor markup--p-anchor" rel="noopener"    target="_blank">official plugin github repo</a>.</p><p name="8920" class="graf graf--p graf-after--p">The official Apple documentation for <a href="https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/index.html#//apple_ref/doc/uid/TP40014707"  class="markup--anchor markup--p-anchor" rel="nofollow noopener noopener noopener"    target="_blank">HealthKit can be found here</a>.</p><p name="5d1b" class="graf graf--p graf-after--p">Also, make sure your app and AppStore description complies with these <a href="https://developer.apple.com/app-store/review/guidelines/#healthkit"  class="markup--anchor markup--p-anchor" rel="noopener"    target="_blank">Apple review guidelines</a>.</p><h3 name="d8e8" class="graf graf--h3 graf-after--p">Differences between HealthKit and Google&nbsp;Fit</h3><ul class="postList"><li name="1ead" class="graf graf--li graf-after--h3">HealthKit includes medical data (e.g. blood glucose), whereas Google Fit is mainly meant for fitness data (although <a href="https://developers.google.com/android/reference/com/google/android/gms/fitness/data/HealthDataTypes"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener"    target="_blank">now supports some medical data too</a>).</li><li name="039d" class="graf graf--li graf-after--li">HealthKit provides a data model that is not extensible, while Google Fit allows defining custom data types.</li><li name="3b17" class="graf graf--li graf-after--li">HealthKit allows to insert data with the unit of measurement of your choice, and automatically translates units when queried, whereas Google Fit uses fixed units of measurement.</li><li name="0504" class="graf graf--li graf-after--li">HealthKit automatically counts steps and distance when you carry your phone with you and if your phone has the CoreMotion chip. Google Fit does it independently on the HW chip and also detects the kind of activity (sedentary, running, walking, cycling, in vehicle).</li><li name="e830" class="graf graf--li graf-after--li">HealthKit can only compute distance for running/walking activities, while Google Fit can also do so for bicycle events.</li></ul><h3 name="ce66" class="graf graf--h3 graf-after--li">Conclusion:</h3><p name="b555" class="graf graf--p graf-after--h3">In this post, we are introduced to the fitness packages available in iPhone and Android devices. These fitness packages are a complete feature package in itself. But when you want those fitness data for your own Ionic 4 app, or want to write fitness data to the default device fitness package, you can do so with several different Ionic Native plugins available.</p><p name="5f7c" class="graf graf--p graf-after--p graf--trailing">Ionic Health Plugin is the most extensive among these plugins, which allows read and write operations to both iOS HealthKit and Google Fit. It has a variety of query data sets and can perform a wide variety of functions for your app.</p></div></div></section><section name="e55b" class="section section--body section--last"><div class="section-divider"><hr class="section-divider"></div><div class="section-content"><div class="section-inner sectionLayout--insetColumn"><h3 name="b4d2" class="graf graf--h3 graf--leading">References</h3><ul class="postList"><li name="926b" class="graf graf--li graf-after--h3"><a href="https://developer.apple.com/documentation/healthkit#//apple_ref/doc/uid/TP40014707"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://developer.apple.com/documentation/healthkit#//apple_ref/doc/uid/TP40014707</a></li><li name="e7dd" class="graf graf--li graf-after--li"><a href="https://www.forbes.com/sites/leebelltech/2019/01/02/best-health-and-fitness-apps-2019/#45a72f9dca53"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://www.forbes.com/sites/leebelltech/2019/01/02/best-health-and-fitness-apps-2019/#45a72f9dca53</a></li><li name="f7e2" class="graf graf--li graf-after--li"><a href="https://www.wareable.com/apple/how-to-use-apple-health-iphone-fitness-app-960"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://www.wareable.com/apple/how-to-use-apple-health-iphone-fitness-app-960</a></li><li name="ab39" class="graf graf--li graf-after--li"><a href="https://developers.google.com/fit/"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://developers.google.com/fit/</a></li><li name="1c23" class="graf graf--li graf-after--li"><a href="https://alternativeto.net/software/google-fit/"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://alternativeto.net/software/google-fit/</a></li><li name="681b" class="graf graf--li graf-after--li"><a href="https://www.androidcentral.com/google-fit-integration-and-why-you-want-it"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://www.androidcentral.com/google-fit-integration-and-why-you-want-it</a></li><li name="63a0" class="graf graf--li graf-after--li graf--trailing"><a href="https://www.wareable.com/android-wear/android-wear-google-fit-watch-face-widget-lands-along-with-extra-data-1143"  class="markup--anchor markup--li-anchor" rel="nofollow noopener noopener noopener noopener" target="_blank">https://www.wareable.com/android-wear/android-wear-google-fit-watch-face-widget-lands-along-with-extra-data-1143</a></li></ul></div></div></section></div></article></main>