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

Commit 3feb331

Browse files
authored
Merge pull request #243 from NativeScript/hristova/update--enableLocationRequest-usage-in-demo-apps
chore: update demo apps to set enableLocationRequest options
2 parents 4ea7c71 + 2b425e3 commit 3feb331

File tree

10 files changed

+25
-29
lines changed

10 files changed

+25
-29
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 500
7676
| timeout | 5 minutes | How long to wait for a location in ms. |
7777
| 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) |
7878
| 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)|
79-
| iosOpenSettingsIfLocationHasBeenDenied | false | Argument on the `enableLocationRequest`. If true, the settings app will open on iOS so the user can change the location services permission. |
8079

8180
> If iosAllowsBackgroundLocationUpdates is set to true, the following code is required in the info.plist file:
8281
>```
@@ -93,7 +92,7 @@ geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 500
9392
| 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. |
9493
| watchLocation(successCallback: successCallbackType, errorCallback: errorCallbackType, options: Options) | number | Monitor for location change. |
9594
| clearWatch(watchId: number) | void | Stop monitoring for location change. Parameter expected is the watchId returned from `watchLocation`. |
96-
| 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) . |
95+
| 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. |
9796
| isEnabled | Promise\<boolean\>| Resolves `true` or `false` based on the location services availability. |
9897
| distance(loc1: Location, loc2: Location) | number | Calculate the distance between two locations. Returns the distance in meters. |
9998

demo-angular/App_Resources/iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@
4343
<string>UIInterfaceOrientationLandscapeLeft</string>
4444
<string>UIInterfaceOrientationLandscapeRight</string>
4545
</array>
46+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
47+
<string>Need location always and when in use.</string>
4648
</dict>
4749
</plist>

demo-angular/angular.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

demo-angular/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
"zone.js": "^0.9.1"
2929
},
3030
"devDependencies": {
31-
"@nativescript/schematics": "~0.5.0",
31+
"@angular/compiler-cli": "~8.2.0",
32+
"@ngtools/webpack": "~8.2.0",
3233
"nativescript-dev-webpack": "^1.0.0",
3334
"typescript": "~3.5.3"
3435
},
3536
"scripts": {
3637
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'",
3738
"build.plugin": "cd ../src && npm run build"
3839
}
39-
}
40+
}

demo-angular/src/app/home/home.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ export class HomeComponent implements OnInit {
2323
public enableLocationTap() {
2424
geolocation.isEnabled().then(function (isEnabled) {
2525
if (!isEnabled) {
26-
geolocation.enableLocationRequest().then(function () {
27-
}, function (e) {
26+
geolocation.enableLocationRequest(true, true).then(() => {
27+
console.log("User Enabled Location Service");
28+
}, (e) => {
2829
console.log("Error: " + (e.message || e));
30+
}).catch(ex => {
31+
console.log("Unable to Enable Location", ex);
2932
});
3033
}
3134
}, function (e) {

demo-vue/app/App_Resources/iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@
4747
<string>UIStatusBarStyleLightContent</string>
4848
<key>UIViewControllerBasedStatusBarAppearance</key>
4949
<false/>
50+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
51+
<string>Need location always and when in use.</string>
5052
</dict>
5153
</plist>

demo-vue/app/components/Home.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
enableLocationTap: function() {
3737
geolocation.isEnabled().then(function (isEnabled) {
3838
if (!isEnabled) {
39-
geolocation.enableLocationRequest().then(function () { }, function (e) {
39+
geolocation.enableLocationRequest(true, true).then(() => {
40+
console.log("User Enabled Location Service");
41+
}, (e) => {
4042
console.log("Error: " + (e.message || e));
43+
}).catch(ex => {
44+
console.log("Unable to Enable Location", ex);
4145
});
4246
}
4347
}, function (e) {

demo/app/App_Resources/iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@
4343
<string>UIInterfaceOrientationLandscapeLeft</string>
4444
<string>UIInterfaceOrientationLandscapeRight</string>
4545
</array>
46+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
47+
<string>Need location always and when in use.</strin
4648
</dict>
4749
</plist>

demo/app/main-page.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ export function stopBackgroundTap() {
6262
export function enableLocationTap() {
6363
geolocation.isEnabled().then(function (isEnabled) {
6464
if (!isEnabled) {
65-
geolocation.enableLocationRequest(false, true).then(function () {
66-
console.log("allowed location usage");
67-
}, function (e) {
65+
geolocation.enableLocationRequest(true, true).then(() => {
66+
console.log("User Enabled Location Service");
67+
}, (e) => {
6868
console.log("Error: " + (e.message || e));
69+
}).catch(ex => {
70+
console.log("Unable to Enable Location", ex);
6971
});
7072
}
7173
}, function (e) {

src/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
1717
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
1818
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\"",
19-
"plugin.link": "npm link && cd ../demo && npm link nativescript-geolocation && cd ../src",
20-
"plugin.tscwatch": "npm run tsc -- -w",
2119
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios",
2220
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android",
2321
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'"

0 commit comments

Comments
 (0)