Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem accessing stored data.

I'm trying to design an iOS app to simply obtain the steps completed for the day. But I'm learning there's nothing simple about it. I stumbled upon this excellent sample code by user: caroline6927 (by the way, if you're reading this, thanks a ton).

 

After some troubleshooting and hurdles, I finally got it to mostly work and redirect back to the app after the authentication process. The problem is I'm struggling to understand how data (such as the amount of steps) are stored in the code.

 

I'm guessing that the steps data is obtained in this portion of the code:

func stepLoop () {
                            self.getFitbitStepData
                                { (counter, error) in
                                    if let anError = error
                                    {
                                        print(anError)
                                    } else
                                    {
                                        let loop_length: Int = FitbitAPIHelper.sharedInstance.download_date_list.count - 1
                                        if counter! <= loop_length {
                                            stepLoop()
                                        }
                                        if counter == loop_length {
                                            // FitbitAPIHelper.sharedInstance.download_step_counter = 0
                                        }
                                    }
                                    /*NotificationCenter.default.post(name: Notification.Name(rawValue: "data has been stored"), object: json)*/
                            }
                        }

Which is located in the swift file "FitbitAPiHelper". Her code uses libraries Alamofire and JSONSwifty, and I noticed that near the bottom of "FitbitAPiHelper.swift" there was this snippet that appeared to use some JSON save file code to store fitbit data, but I have no idea how to access that save file.

 func saveJSONandCheck(_ JSONfile: AnyObject, _ file_name: String) {
        let savedJSON = FileSaveHelper(fileName:file_name, fileExtension: .JSON, subDirectory: "FitbitData", directory: .documentDirectory)
        do {
            try savedJSON.saveFile(dataForJson: JSONfile)
        }
        catch {
            print(error)
        }
        // print("JSON file exists: \(savedJSON.fileExists)")
    }

All I'm really hoping for at this point is to carry out OAuth 2.0 process to sign in a user, obtain their steps count for the day, and assign that number to a variable. Which I thought wouldn't be too complicated, but I'm quickly finding myself in over my head. Any help would be greatly appreciated, and I apologize for the lack of expertise you guys are used to.

Best Answer
0 Votes
0 REPLIES 0