Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change approach to match general Options interface
  • Loading branch information
bradmartin committed Jan 9, 2019
commit 0d605024aecc1a80588fb0a678cc888a0757d0ea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 500
| timeout | 5 minutes | How long to wait for a location in ms. |
| iosAllowsBackgroundLocationUpdates | false | If enabled, UIBackgroundModes key in info.plist is required (check the hint below). Allow the application to receive location updates in background (ignored on Android). Read more in [Apple document](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates?language=objc) |
| iosPausesLocationUpdatesAutomatically | true | Allow deactivation of the automatic pause of location updates (ignored on Android). Read more in [Apple document](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620553-pauseslocationupdatesautomatical?language=objc)|
| iosOpenSettingsIfLocationIsDisabled | false | If true when the `isEnabled` method is invoked, the settings app will open on iOS so the user can change the location services permission. |


> If iosAllowsBackgroundLocationUpdates is set to true, the following code is required in the info.plist file:
>```
Expand Down
8 changes: 1 addition & 7 deletions src/geolocation.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ export class LocationBase implements LocationDef {
export const defaultGetLocationTimeout = 5 * 60 * 1000; // 5 minutes
export const minRangeUpdate = 0.1; // 0 meters
export const minTimeUpdate = 1 * 60 * 1000; // 1 minute
export const fastestTimeUpdate = 5 * 1000; // 5 secs

export interface IsEnabledOptions {
ios: {
openSettingsIfLocationIsDisabled: boolean;
}
}
export const fastestTimeUpdate = 5 * 1000; // 5 secs
8 changes: 3 additions & 5 deletions src/geolocation.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import * as utils from "tns-core-modules/utils/utils";
import {
LocationBase,
defaultGetLocationTimeout,
minRangeUpdate,
IsEnabledOptions
minRangeUpdate
} from "./geolocation.common";
import {
Options,
Expand Down Expand Up @@ -277,13 +276,12 @@ function _isEnabled(options?: Options): boolean {
return false;
}

export function isEnabled(options: IsEnabledOptions): Promise<boolean> {
export function isEnabled(options: Options): Promise<boolean> {
return new Promise(function (resolve, reject) {
const isEnabledResult = _isEnabled();
if (isEnabledResult === false) {
if (options &&
options.ios &&
options.ios.openSettingsIfLocationIsDisabled === true
options.iosOpenSettingsIfLocationIsDisabled === true
) {
utils.ios.getter(UIApplication, UIApplication.sharedApplication).openURL(NSURL.URLWithString(UIApplicationOpenSettingsURLString));
}
Expand Down
106 changes: 58 additions & 48 deletions src/location-monitor.d.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
import { Location } from "./location";

/**
* Provides options for location monitoring.
*/
* Provides options for location monitoring.
*/
export interface Options {
/**
* Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH
*/
desiredAccuracy?: number;

/**
* Update distance filter in meters. Specifies how often to update. Default is no filter
*/
updateDistance?: number;

/**
* Interval between location updates, in milliseconds (ignored on iOS)
*/
updateTime?: number;

/**
* Minimum time interval between location updates, in milliseconds (ignored on iOS)
*/
minimumUpdateTime?: number;

/**
* How old locations to receive in ms.
*/
maximumAge?: number;

/**
* How long to wait for a location in ms.
*/
timeout?: number;

/**
* A Boolean value which has to be set to true on iOS versions > 9.0 to allow the application to receive location updates in
* background in combination with the UIBackgroundModes key 'location' in the Info.plist. An exception is thrown if the
* property is enabled without the UIBackgroundModes key set to true. The value is ignored on Android.
* @see {@link https://developer.apple.com/reference/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates|allowsBackgroundLocationUpdates}
*/
iosAllowsBackgroundLocationUpdates?: boolean;

/**
* A Boolean value which has to be set to false on iOS to deactivate the automatic pause of location updates. The location manager might pause
* location updates for a period of time to improve battery life. This behavior may stop a long-running background task. Set this flag to false
* to prevent this behavior. The value is ignored on Android.
* @see {@link https://developer.apple.com/reference/corelocation/cllocationmanager/1620553-pauseslocationupdatesautomatical|pausesLocationUpdatesAutomatically}
*/
iosPausesLocationUpdatesAutomatically?: boolean;
/**
* Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH
*/
desiredAccuracy?: number;

/**
* Update distance filter in meters. Specifies how often to update. Default is no filter
*/
updateDistance?: number;

/**
* Interval between location updates, in milliseconds (ignored on iOS)
*/
updateTime?: number;

/**
* Minimum time interval between location updates, in milliseconds (ignored on iOS)
*/
minimumUpdateTime?: number;

/**
* How old locations to receive in ms.
*/
maximumAge?: number;

/**
* How long to wait for a location in ms.
*/
timeout?: number;

/**
* A Boolean value which has to be set to true on iOS versions > 9.0 to allow the application to receive location updates in
* background in combination with the UIBackgroundModes key 'location' in the Info.plist. An exception is thrown if the
* property is enabled without the UIBackgroundModes key set to true. The value is ignored on Android.
* @see {@link https://developer.apple.com/reference/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates|allowsBackgroundLocationUpdates}
*/
iosAllowsBackgroundLocationUpdates?: boolean;

/**
* A Boolean value which has to be set to false on iOS to deactivate the automatic pause of location updates. The location manager might pause
* location updates for a period of time to improve battery life. This behavior may stop a long-running background task. Set this flag to false
* to prevent this behavior. The value is ignored on Android.
* @see {@link https://developer.apple.com/reference/corelocation/cllocationmanager/1620553-pauseslocationupdatesautomatical|pausesLocationUpdatesAutomatically}
*/
iosPausesLocationUpdatesAutomatically?: boolean;

/**
* A boolean value which if set to true, the application will open the Settings app
* on iOS so the user can change the permission for location when the isEnabled method is invoked.
*/
iosOpenSettingsIfLocationIsDisabled?: boolean;
}

declare type successCallbackType = (location: Location) => void;
Expand All @@ -64,7 +70,11 @@ export function getCurrentLocation(options: Options): Promise<Location>;
* Monitor for location change.
* @returns {number} The watch id
*/
export function watchLocation(successCallback: successCallbackType, errorCallback: errorCallbackType, options: Options): number;
export function watchLocation(
successCallback: successCallbackType,
errorCallback: errorCallbackType,
options: Options
): number;

/**
* Stop monitoring for location change. Parameter expected is the watchId returned from `watchLocation`.
Expand Down