Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS GPS support #116

Merged
merged 2 commits into from
Mar 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions plyer/platforms/ios/gps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'''
iOS GPS
-----------
'''

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 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):
self._location_manager.stopUpdatingLocation()

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

self.on_location(
lat=location.coordinate.a,
lon=location.coordinate.b,
speed=location.speed,
bearing=location.course, # TODO: check if bearing and course is same
altitude=location.altitude)


def instance():
return iOSGPS()