From d8d0e7adad345f9533dc28e7787cf38c6d0ce2bb Mon Sep 17 00:00:00 2001 From: laltin Date: Wed, 4 Mar 2015 00:34:21 +0200 Subject: [PATCH 1/2] first working version --- plyer/platforms/ios/gps.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plyer/platforms/ios/gps.py diff --git a/plyer/platforms/ios/gps.py b/plyer/platforms/ios/gps.py new file mode 100644 index 000000000..039be4092 --- /dev/null +++ b/plyer/platforms/ios/gps.py @@ -0,0 +1,46 @@ +''' +iOS GPS +----------- +''' +import logging +from pyobjus import autoclass, protocol +from pyobjus.dylib_manager import load_framework +from plyer.facades import GPS + +load_framework('/System/Library/Frameworks/CoreLocation.framework') +CLLocationManager = autoclass('CLLocationManager') + + +class iOSGPS(GPS): + def _configure(self): + if not hasattr(self, '_location_manager'): + self._location_manager = CLLocationManager.alloc().init() + + def _start(self): + self._location_manager.delegate = self + + self._location_manager.requestWhenInUseAuthorization() # NSLocationWhenInUseUsageDescription, goes to pause mode + self._location_manager.startUpdatingLocation() + + def _stop(self): + self._location_manager.stopUpdatingLocation() + + @protocol('CLLocationManagerDelegate') + def locationManager_didUpdateLocations_(self, manager, locations): + logging.info("locatino updated") + + location = locations.lastObject #.objectAtIndex(locations.count() - 1) # last one is the most recent + location = manager.location + logging.info(str(dir(location))) + logging.info(str(dir(location.coordinate))) + + self.on_location( + lat=location.coordinate.a, + lon=location.coordinate.b, + speed=location.speed, + bearing=location.course, # TODO: + altitude=location.altitude) + + +def instance(): + return iOSGPS() From 83cab2dd1ddb4d22c077a40774b827689f05370a Mon Sep 17 00:00:00 2001 From: laltin Date: Wed, 4 Mar 2015 01:06:53 +0200 Subject: [PATCH 2/2] cleanup & comment --- plyer/platforms/ios/gps.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plyer/platforms/ios/gps.py b/plyer/platforms/ios/gps.py index 039be4092..2262d1262 100644 --- a/plyer/platforms/ios/gps.py +++ b/plyer/platforms/ios/gps.py @@ -2,7 +2,7 @@ iOS GPS ----------- ''' -import logging + from pyobjus import autoclass, protocol from pyobjus.dylib_manager import load_framework from plyer.facades import GPS @@ -19,7 +19,11 @@ def _configure(self): def _start(self): self._location_manager.delegate = self - self._location_manager.requestWhenInUseAuthorization() # NSLocationWhenInUseUsageDescription, goes to pause mode + self._location_manager.requestWhenInUseAuthorization() + # NSLocationWhenInUseUsageDescription key must exist in Info.plist + # file. When the authorization prompt is displayed your app goes + # into pause mode and if your app doesn't support background mode + # it will crash. self._location_manager.startUpdatingLocation() def _stop(self): @@ -27,18 +31,13 @@ def _stop(self): @protocol('CLLocationManagerDelegate') def locationManager_didUpdateLocations_(self, manager, locations): - logging.info("locatino updated") - - location = locations.lastObject #.objectAtIndex(locations.count() - 1) # last one is the most recent location = manager.location - logging.info(str(dir(location))) - logging.info(str(dir(location.coordinate))) self.on_location( lat=location.coordinate.a, lon=location.coordinate.b, speed=location.speed, - bearing=location.course, # TODO: + bearing=location.course, # TODO: check if bearing and course is same altitude=location.altitude)