Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #243 from NativeScript/hristova/update--enableLoca…
Browse files Browse the repository at this point in the history
…tionRequest-usage-in-demo-apps

chore: update demo apps to set enableLocationRequest options
  • Loading branch information
elena-p authored Sep 13, 2019
2 parents 4ea7c71 + 2b425e3 commit 3feb331
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ 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)|
| iosOpenSettingsIfLocationHasBeenDenied | false | Argument on the `enableLocationRequest`. If true, 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 All @@ -93,7 +92,7 @@ geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 500
| getCurrentLocation(options: Options) | Promise<Location> | Get current location applying the specified options (if any). Since version 5.0 of the plugin, it will use [requestLocation](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620548-requestlocation?language=objc) API for devices using iOS 9.0+. In situation of poor or no GPS signal, but available Wi-Fi it will take 10 sec to return location. |
| watchLocation(successCallback: successCallbackType, errorCallback: errorCallbackType, options: Options) | number | Monitor for location change. |
| clearWatch(watchId: number) | void | Stop monitoring for location change. Parameter expected is the watchId returned from `watchLocation`. |
| enableLocationRequest(always?: boolean) | Promise\<void\> | Ask for permissions to use location services. The option `always` is applicable only for iOS. For a custom prompt message on IOS, the following keys are required: [NSLocationAlwaysAndWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysandwheninuseusagedescription) (iOS 11.0+) OR [NSLocationAlwaysUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription?language=objc) (iOS 8.0-10.0) and [NSLocationWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationwheninuseusagedescription). Read more about [request always usage](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization) . |
| enableLocationRequest(always?: boolean, iosOpenSettingsIfLocationHasBeenDenied?: boolean) | Promise\<void\> | Ask for permissions to use location services. The options are applicable only for iOS. When `always` is true, it opens a custom prompt message and the following keys are required: [NSLocationAlwaysAndWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysandwheninuseusagedescription) (iOS 11.0+) OR [NSLocationAlwaysUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription?language=objc) (iOS 8.0-10.0) and [NSLocationWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationwheninuseusagedescription). Read more about [request always usage](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization) . When `iosOpenSettingsIfLocationHasBeenDenied` is true, the settings app will open on iOS so the user can change the location services permission. |
| isEnabled | Promise\<boolean\>| Resolves `true` or `false` based on the location services availability. |
| distance(loc1: Location, loc2: Location) | number | Calculate the distance between two locations. Returns the distance in meters. |

Expand Down
2 changes: 2 additions & 0 deletions demo-angular/App_Resources/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need location always and when in use.</string>
</dict>
</plist>
17 changes: 0 additions & 17 deletions demo-angular/angular.json

This file was deleted.

5 changes: 3 additions & 2 deletions demo-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"zone.js": "^0.9.1"
},
"devDependencies": {
"@nativescript/schematics": "~0.5.0",
"@angular/compiler-cli": "~8.2.0",
"@ngtools/webpack": "~8.2.0",
"nativescript-dev-webpack": "^1.0.0",
"typescript": "~3.5.3"
},
"scripts": {
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'",
"build.plugin": "cd ../src && npm run build"
}
}
}
7 changes: 5 additions & 2 deletions demo-angular/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export class HomeComponent implements OnInit {
public enableLocationTap() {
geolocation.isEnabled().then(function (isEnabled) {
if (!isEnabled) {
geolocation.enableLocationRequest().then(function () {
}, function (e) {
geolocation.enableLocationRequest(true, true).then(() => {
console.log("User Enabled Location Service");
}, (e) => {
console.log("Error: " + (e.message || e));
}).catch(ex => {
console.log("Unable to Enable Location", ex);
});
}
}, function (e) {
Expand Down
2 changes: 2 additions & 0 deletions demo-vue/app/App_Resources/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need location always and when in use.</string>
</dict>
</plist>
6 changes: 5 additions & 1 deletion demo-vue/app/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
enableLocationTap: function() {
geolocation.isEnabled().then(function (isEnabled) {
if (!isEnabled) {
geolocation.enableLocationRequest().then(function () { }, function (e) {
geolocation.enableLocationRequest(true, true).then(() => {
console.log("User Enabled Location Service");
}, (e) => {
console.log("Error: " + (e.message || e));
}).catch(ex => {
console.log("Unable to Enable Location", ex);
});
}
}, function (e) {
Expand Down
2 changes: 2 additions & 0 deletions demo/app/App_Resources/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need location always and when in use.</strin
</dict>
</plist>
8 changes: 5 additions & 3 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export function stopBackgroundTap() {
export function enableLocationTap() {
geolocation.isEnabled().then(function (isEnabled) {
if (!isEnabled) {
geolocation.enableLocationRequest(false, true).then(function () {
console.log("allowed location usage");
}, function (e) {
geolocation.enableLocationRequest(true, true).then(() => {
console.log("User Enabled Location Service");
}, (e) => {
console.log("Error: " + (e.message || e));
}).catch(ex => {
console.log("Unable to Enable Location", ex);
});
}
}, function (e) {
Expand Down
2 changes: 0 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\"",
"plugin.link": "npm link && cd ../demo && npm link nativescript-geolocation && cd ../src",
"plugin.tscwatch": "npm run tsc -- -w",
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios",
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android",
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'"
Expand Down

0 comments on commit 3feb331

Please sign in to comment.