DIY: Hack Weward for iOS

Weward is a mobile app that basically pay-you if you walk; offer also a price exchange and lots of offers inside the app.

The first time I opened it, I see at glance that I can hack it… and of course you can do it by yourself, very quick and easily. Let’s see how.


• You need a Mac Book

• You need XCode

• You need an iPhone

You don’t need to be a developer, you don’t need to know programming languages… but if you want to learn, you’re welcome! 

 Create a new project

  1. Open XCode and create a new App project. Give it the name you want and press NEXT.

2. Add permission in order to use HealthKit functions.

3. Add the explicit messages to show why you want to access to HealthKit (useless of course for this example, but necessary to work):

Cool, 50% of our app is done! 


 A little bit of code:

Open the ViewController.swift. We need to add as import the HealthKit, so add it below UIKit:

import HealthKit

Ignore for now the viewDidLoad method, we come back later…

Add authorizations

We need to handle authorization for using HealthKit, I’ve prepared a simple authorization function, you can copy/paste wildly where you prefer, of course, outside of viewDidLoad.

private func authorizeHealthKit(completion: @escaping (Bool) -> Void) {
    guard HKHealthStore.isHealthDataAvailable() else {
        completion(false)
        return
    }
    
    guard let stepsCount = HKObjectType.quantityType(forIdentifier: .stepCount) else {
        completion(false)
        return
    }
    HKHealthStore().requestAuthorization(toShare: [stepsCount], read: nil) { success, _ in
        completion(success)
    }
}
TL;DR 

Line 2: is used to check if you iOS have HealthKit available

Line 7: identify the type of data you want to use

Line 12: request effectively the authorization and show a popup with toggles


Save custom steps

As previous piece of code, you can copy/paste again also this snippet. Is used to save in your Health app the custom steps you want:

private func saveSteps(stepsCountValue: Int, date: Date, completion: @escaping (Error?) -> Void) {
    guard let stepCountType = HKQuantityType.quantityType(forIdentifier: .stepCount) else {
        fatalError("failed")
    }
    let stepsCountQuantity = HKQuantity(
        unit: HKUnit.count(),
        doubleValue: Double(stepsCountValue)
    )
    let stepsCountSample = HKQuantitySample(
        type: stepCountType,
        quantity: stepsCountQuantity,
        start: date,
        end: date
    )
    
    HKHealthStore().save(stepsCountSample) { (success, error) in
        if let error = error {
            completion(error)
        } else {
            completion(nil)
            print("Successfully saved Steps Count Sample")
        }
    }
}
TL;DR

Line 1: is the function caller that accept as parameter the number of steps you want to save and the date of when to save!

Line 6: create the “quantity” aka steps you want to save

Line 11: create the data structure as the HealthKit format request and set the date (start / end date are equals because we want the single day).

Line 18: save the steps.


Make it works!

Well, now we can go back in our viewDidLoad function, and after super.viewDidLoad(), we can paste this:

authorizeHealthKit { _ in
    self.saveSteps(stepsCountValue: 25123, date: Date()) { _ in
        print("saved!")
    }
}

as you can see, stepsCountValue are the steps you want to save.

Please note that Weward accept maximum 25000 steps for day, so is useless to put a huge number. It will be ignored.

But in this way you can set the precise number (for some special missions is useful!)…


Run the app

Now, attach you device to your Mac , and press the RUN ▶️ button!

Your app will be something like this:

At first run, you need to confirm that you are aware that your app want to write steps in Health app (image 01).

Once accepted, you will see a white screen (your empty app, Image 02).

Now you can open Health app to verify if steps are written (Image 03) and open Weward to reward your steps!

weward hack iOS
Weward fake step counter

Bonus: shake for random steps

You probably want to save every day, different random steps in a useful range. You can add a shake function that save for you randomly value of steps.

Copy/paste where you want (is a system method). No need to add other stuffs:

override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
    if motion == .motionShake {
        let steps = Int.random(in: 25000...30000)
        saveSteps(stepsCountValue: steps, date: Date()) { _ in
            print("saved!")
        }
    }
}

Enjoy and… remember to walk! 


BONUS^2: have fun with other apps

• Want also to capture Pokemon 朗 from your desk (with Pokemon-Go), take a look here: https://www.albertopasca.it/whiletrue/pokemongo-catch-world-wide-pokemon-from-your-desk/

• You probably want also to impress your friends with Strava 朗 (or other GPS tracker)? Make your custom GPS circuit and press record: https://www.albertopasca.it/whiletrue/ios-fake-gps-position-how-to-use-and-prevent/

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.