Tutorials /

Building ResearchKit apps on Kinvey

ResearchKit is Apple's iOS framework for medical research apps. From Apple's ResearchKit page -

ResearchKit is an open source framework introduced by Apple that allows researchers and developers to create powerful apps for medical research. Easily create visual consent flows, real-time dynamic active tasks, and surveys using a variety of customizable modules that you can build upon and share with the community.

ResearchKit provides developers a broad range of UI and model classes that make it easy to build workflows specific to medical research apps. ResearchKit leaves the responsibility of persistence and synchronization of data to the developer. This is where Kinvey comes in.

Kinvey provides a HIPAA compliant backend platform for healthcare apps, as well as SDKs that interface with the backend and add client side capabilities such as caching, user management, data synchronization etc. We integrated our iOS SDK with ResearchKit, so that developers have a toolkit to quickly spin up research apps that are backed by a compliant backend. The outcome of our integration is KinveyResearchKit, a SDK wrapper to ResearchKit that augments ResearchKit classes with Kinvey functionality.

Getting Started

Kinvey's ResearchKit integration is available in our open source github repository. The repo contains the "KinveyResearchKit" wrapper SDK and a sample called "ORKCatalog".

The Getting Started section of the README describes how to set up the codebase and test it out.

How it works

The KinveyResearchKit SDK contains classes that wrap ResearchKit and augment it with Kinvey functionality. The KinveyResearchKit SDK has two main components -

Model wrappers (subclasses of Result)

These classes add property mapping and transformations, as described in our Data Store guide, to the ResearchKit model classes. These wrapper classes enable you to use all of ResearchKit's Result subclasses with the full range of Kinvey Data Store functionality, including caching and sync. The code below shows a data store created to save TaskResult objects to the backend. You can find this code in the ResultViewController class in ORKCatalog -

lazy var resultStore = DataStore<TaskResult>.collection(.network)
... { savedResult, error in

Login flow

The KinveyResearchKit SDK extends the classes that implement the login workflow in ResearchKit. These subclasses add logic to manage users in the Kinvey backend. All the key user operations such as signup, login, logout, email verification etc are integrated with Kinvey's user store. The LoginStepViewController class adds Kinvey login capabilities to the ResearchKit ORKLoginStepViewController class, as shown in the snippet below.

open class LoginStepViewController: ORKWaitStepViewController {

    open override func viewDidAppear(_ animated: Bool) {

        User.login(username: email, password: password) {
            switch $0 {
            case .success(let user):
            case .failure(let error):

Using KinveyResearchKit in your own project

To illustrate how you can start using KinveyResearchKit in your own app projects, we modified Apple's ORKCatalog sample and made it a Kinvey-backed app. We made the following changes -

  • Added framework dependencies to Kinvey and KinveyResearchKit.
  • Added code in the AppDelegate to initialize Kinvey and login a user (as described in our Getting Started guide).
  • Created a DataStore to save ORKResult objects to Kinvey. For every ORKResult, setting the ResultViewController.result property also saves the result to Kinvey (refer to the Data Store guide for details on how to save data to Kinvey)

What's next

We love to hear from developers about what they're building and where they'd like us to improve. Our ResearchKit integration is open source, and we welcome your contributions and feedback. Feel free to get in touch with us through github or Kinvey support.

Here are some things we have on our roadmap -