kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.61k stars 427 forks source link

Weird GPS issue on iOS 10 #240

Closed gorgonaut04 closed 11 months ago

gorgonaut04 commented 7 years ago

On iOS 10 devices and simulators, the lat/lon are not available when the delegate function / callback locationManagerdidUpdateLocation() is called. The data structure is inexplicably incorrect. "manager.location" is of type CLLocation (correct), but when trying to access manager.location.coordinate, of type CLLocationCoordinate2D on iOS 8/9, I get the error "not enough parameters for coordinate" on iOS 10. What?? Should this be a plyer or pyobjus issue? I can't understand how this could be happening just in kivy!

My current workaround is to get the debugprint member from manager.location, and parse that string for the lat/lon and accuracy. It works, but the docs claim this is deprecated...

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/39110292-weird-gps-issue-on-ios-10?utm_campaign=plugin&utm_content=tracker%2F77151&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F77151&utm_medium=issues&utm_source=github).
gorgonaut04 commented 7 years ago

Just to confirm, everything was working fine in iOS 8 & 9. The only thing that changed was that users updated their phones to iOS 10 and stopped getting GPS position updates.

doratoa commented 7 years ago

Regrettably I confirm the problem, my friend have just updated to iOS 10 and GPS stopped working. Can't verify since I don't have real devices, but Simulators don't seem to use mock locations too. @gorgonaut04 do you mind sharing code for your workaround while issue is not solved?

gorgonaut04 commented 7 years ago

I've only parsed out lat/lon and accuracy, so if you need speed, bearing, or altitude, you'll need to parse them out as well. Make sure you get the latest kivy ios, or else the lack of prints/logging on iOS 10 without that fix will make things very difficult!

'''
iOS GPS
-----------
'''
    @protocol('CLLocationManagerDelegate')
    def locationManager_didUpdateLocations_(self, manager, locations):
        location = manager.location
        description = location.description.UTF8String()
        lat, lon = [float(coord) for coord in description.split('<')[-1].split('>')[0].split(',')]
        acc = float(description.split(' +/- ')[-1].split('m ')[0])

        self.on_location(lat=lat, lon=lon, accuracy=acc)
doratoa commented 7 years ago

Thank you, @gorgonaut04 We have a live app in AppStore and it was very bad news for us if GPS breaks on iOS 10 update. Have to patch it asap, and i don't really have experience with Pyobjus yet. But I'll try to figure out something after.

gorgonaut04 commented 7 years ago

Same here! We faced this a month or so ago and I literally pulled an all-nighter trying to fight through the combined lack lack of prints/logs and this problem. Eventually cobbled together my own print statement using NSLog, via pyobjus On Fri, Nov 11, 2016 at 6:15 PM Valentine Davydov notifications@github.com wrote:

Thank you, @gorgonaut04 https://github.com/gorgonaut04 We have a live app in AppStore and it was very bad news for us if GPS breaks on iOS 10 update. Have to patch it asap, and i don't really have experience with Pyobjus yet. But I'll try to figure out something after.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kivy/plyer/issues/240#issuecomment-260095228, or mute the thread https://github.com/notifications/unsubscribe-auth/AKTLx1i6lkaiur1dcGbH7dvFIcFmVCPOks5q9SFMgaJpZM4KuNl_ .

doratoa commented 7 years ago

Thanks, you workaround seems to work pretty fine, simulators for both 9.3 and 10.0 handle mock location OK too. I'll try to if not get to the core of original problem myself, then pointing community attention to it.

kennedyshead commented 7 years ago

+1 for this issue!

zoltan-fedor commented 7 years ago

+1

SoundsSerious commented 6 years ago

Heyo! It seems like this error is occuring deeper in pyobjus but I expanded on the string parsing hack above to add accuracy speed course and altitude. We should push something out soon. GPS is critical for many apps and we don't want the project kivy to suffer a lapse. Let me know if i can help here :)

    @protocol('CLLocationManagerDelegate')
    def locationManager_didUpdateLocations_(self, manager, locations):
        location = manager.location

        description = location.description.UTF8String()
        lat, lon = [float(coord) for coord in description.split('<')[-1].split('>')[0].split(',')]
        acc = float(description.split(' +/- ')[-1].split('m ')[0])

        speed=location.speed
        altitude=location.altitude
        course=location.course

        self.on_location(
            lat=lat,
            lon=lon,
            speed=speed,
            bearing=course,
            altitude=altitude,
            accuracy = acc)
glins97 commented 6 years ago

Stuck on the same boat right now. I'm quite new to all this and could not figure out how to make the code above work.

Any hints?

doratoa commented 6 years ago

@glins97 have you patched your ios gps with @gorgonaut04 code? My App still uses it

glins97 commented 6 years ago

Yeah, it works! For those that might be unsure how to proceed, all you have to do is replace plyer/platforms/ios/gps.py with the function above. Cheers.

tshirtman commented 6 years ago

not an ios user myself, but seems like this code should be made into a pull request to benefit more users.

thanks.

HourGlss commented 5 years ago

is this fixed?

Dirk-Sandberg commented 5 years ago

@glins97 Where exactly is the gps.py file? I have found 3 gps.py files, and none of them seem to work when I insert the code above - it appears that the files I found aren't executing at all (i put some print statements in). The three files I found were

/foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/build/lib/plyer/platforms/ios/gps.py

/foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/iosbuild/lib/python2.7/site-packages/plyer/platforms/ios/gps.py

foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/plyer/platforms/ios/gps.py

I tried to update my project with ./toolchain.py update project-name as well

gorgonaut04 commented 5 years ago

You have to make sure you delete any "gps.pyo" files in order to force the .py file to be re-compiled. That should help you narrow down the critical file (I apologize, it's been a couple years, so I don't remember which file is the critical one to edit.)

On Sat, Apr 13, 2019 at 8:55 PM ESandberg notifications@github.com wrote:

@glins97 https://github.com/glins97 Where exactly is the gps.py file? I have found 3 gps.py files, and none of them seem to work when I insert the code above - it appears that the files I found aren't executing at all (i put some print statements in). The three files I found were

/foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/build/lib/plyer/platforms/ios/gps.py

/foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/iosbuild/lib/python2.7/site-packages/plyer/platforms/ios/gps.py

foo/bar/kivy-ios/build/plyer/x86_64/plyer-master/plyer/platforms/ios/gps.py

I tried to update my project with ./toolchain.py update project-name as well

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kivy/plyer/issues/240#issuecomment-482917693, or mute the thread https://github.com/notifications/unsubscribe-auth/AKTLx0JbdLGVOroDkExDpfO-DHKtG05_ks5vgqa_gaJpZM4KuNl_ .