Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions demo/app/tests/mock-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ var MockLocationManager = (function () {
return _this._requestSingleUpdate(_this.delegate, _this);
}, 500);
};
MockLocationManager.prototype.requestLocation = function () {
var _this = this;
this.removeUpdates(null);
MockLocationManager.intervalId = setTimeout(function () {
// this.delegate is the location listener
return _this._requestSingleUpdate(_this.delegate, _this);
}, 500);
};
MockLocationManager.prototype._requestSingleUpdate = function (locListener, instance) {
var newLocation = {
coordinate: {
Expand Down
34 changes: 6 additions & 28 deletions src/geolocation.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ function errorHandler(errData: UnhandledErrorEventData) {
}
}

function getVersionMaj () {
return parseInt(Platform.device.osVersion.split(".")[0]);
}

// options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout
export function getCurrentLocation(options: Options): Promise<Location> {
return new Promise(function (resolve, reject) {
Expand All @@ -168,7 +164,6 @@ export function getCurrentLocation(options: Options): Promise<Location> {
} else {
let timerId;
let locListener;
let initLocation;

let stopTimerAndMonitor = function (locListenerId) {
if (timerId !== undefined) {
Expand All @@ -179,30 +174,18 @@ export function getCurrentLocation(options: Options): Promise<Location> {
};

let successCallback = function (location: Location) {
if (getVersionMaj() < 9) {
if (typeof options.maximumAge === "number" && location.timestamp.valueOf() + options.maximumAge < new Date().valueOf()) {
// returned location is too old, but we still have some time before the timeout so maybe wait a bit?
return;
}

if (options.desiredAccuracy !== Accuracy.any && !initLocation) {
// regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested
initLocation = location;
return;
}
if (typeof options.maximumAge === "number" && location.timestamp.valueOf() + options.maximumAge < new Date().valueOf()) {
// returned location is too old, but we still have some time before the timeout so maybe wait a bit?
return;
}

stopTimerAndMonitor(locListener.id);
resolve(location);
};

locListener = LocationListenerImpl.initWithLocationError(successCallback, reject);
locListener = LocationListenerImpl.initWithLocationError(successCallback);
try {
if (getVersionMaj() >= 9) {
LocationMonitor.requestLocation(options, locListener);
} else {
LocationMonitor.startLocationMonitoring(options, locListener);
}
LocationMonitor.startLocationMonitoring(options, locListener);
} catch (e) {
stopTimerAndMonitor(locListener.id);
reject(e);
Expand Down Expand Up @@ -338,11 +321,6 @@ export class LocationMonitor {
return null;
}

static requestLocation(options: Options, locListener: any): void {
let iosLocManager = getIOSLocationManager(locListener, options);
iosLocManager.requestLocation();
}

static startLocationMonitoring(options: Options, locListener: any): void {
let iosLocManager = getIOSLocationManager(locListener, options);
iosLocManager.startUpdatingLocation();
Expand All @@ -364,7 +342,7 @@ export class LocationMonitor {
iosLocManager.distanceFilter = options ? options.updateDistance : minRangeUpdate;
locationManagers[locListener.id] = iosLocManager;
locationListeners[locListener.id] = locListener;
if (getVersionMaj() >= 9) {
if (parseInt(Platform.device.osVersion.split(".")[0]) >= 9) {
iosLocManager.allowsBackgroundLocationUpdates =
options && options.iosAllowsBackgroundLocationUpdates != null ?
options.iosAllowsBackgroundLocationUpdates : false;
Expand Down