Download sensor data as a csv file

edited August 2021 in iOS

Hello, I am developing the sensor logging iOS application. I want to make the data stored in the sensor download as a csv file when the user presses the button on the screen. I tried to implement such function in the "mbl_mw_logger_subscribe" as below.

    mbl_mw_logger_subscribe(logger, bridge(obj: self)) { (context, obj) in
                let acceleration: MblMwCartesianFloat = obj!.pointee.valueAs()  
                let fileManager = FileManager.default
                let documentURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
                let fileURL = documentURL.appendingPathComponent("accelerometer.csv")
                var accelLog: NSString = ""
            ...}

However, I realized that this would not work because the file would be initialized each time the closure was called. I should define them outside the closure, but if I do that, the error, "A C function pointer cannot be formed from a closure that captures context" occurs.
How can I solve this? Or is there any other way to implement this function?

Comments

Sign In or Register to comment.