onnela-lab / beiwe-ios

Beiwe is a smartphone-based digital phenotyping research platform. This is the Beiwe iOS app code. The Beiwe2 app is also available on the Apple app store to use with open source builds of the Beiwe backend.
https://www.beiwe.org/
BSD 3-Clause "New" or "Revised" License
21 stars 13 forks source link

"reachabliity" - detecting if the device has network access - does not appear to work. #45

Open biblicabeebli opened 6 months ago

biblicabeebli commented 6 months ago

If I enable airplane mode while testing (I was testing uploads) it still tries to upload.

    let reachable = studySettings.uploadOverCellular ? 
        self.appDelegate.reachability!.isReachable : self.appDelegate.reachability!.isReachableViaWiFi

    // other stuff

    // logic for running uploads code
    if now > nextUpload || (reachable && currentStudy.missedUploadCheck) {
        // This (missedUploadCheck?) will be saved because setNextUpload saves the study
        currentStudy.missedUploadCheck = !reachable // if not reachable we missed the upload check
        self.setNextUploadTime()
        if reachable {
            self.upload()
        }
    }
biblicabeebli commented 5 months ago
biblicabeebli commented 5 months ago

WOW this has become difficult: https://stackoverflow.com/questions/30743408/check-for-internet-connection-with-swift?page=1&tab=scoredesc#tab-top

Old behavior always returned connected on wifi. Added app entitlement that changed to completely block this back in ios 13. Old Reachability.swift appears to be broken, the stack overflow post has a huge comment thread on problems with the top solution.

Alamofire seems to have something very similar built in but it has similar bugs, probably because we are on an old version.

biblicabeebli commented 5 months ago

I have had to reimplement Reachability.

Reachability is a data stream that indicates what internet mode the device is in, e.g. wifi, cellular, or unreachable. The library used was last updated for iOS 10 and cannot be made compatible again.

Reachability and probably upload-over-cellular was non-functional on all iOS versions since September 13, 2016.

Cool. Great. Fun.

For technical reasons determining "unreachable" is very, very difficult to do cleanly. The reachability data stream now only says "wifi" or "cellular", with "cellular" potentially meaning no connection. Restoring "unreachable" is potentially feasible, but requires the app do an extra network operation quite frequently.

The upload-over-cellular study setting has been fixed.

biblicabeebli commented 5 months ago

pushing to build 2024.19

biblicabeebli commented 5 months ago

@hydawo I expect someone somewhere will want to know about this kerfuffle.

biblicabeebli commented 4 months ago

This issue is not of critical importance, if anyone wants this data stream upgraded/fixed they can comment on this thread, we will keep this thread open.