diff --git a/README.md b/README.md index 239e767..20396c5 100644 --- a/README.md +++ b/README.md @@ -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: >``` @@ -93,7 +92,7 @@ geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 500 | getCurrentLocation(options: Options) | Promise | 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\ | 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\ | 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\| 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. | diff --git a/demo-angular/App_Resources/iOS/Info.plist b/demo-angular/App_Resources/iOS/Info.plist index ea3e3ea..84967b7 100644 --- a/demo-angular/App_Resources/iOS/Info.plist +++ b/demo-angular/App_Resources/iOS/Info.plist @@ -43,5 +43,7 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + NSLocationAlwaysAndWhenInUseUsageDescription + Need location always and when in use. diff --git a/demo-angular/angular.json b/demo-angular/angular.json deleted file mode 100644 index ef95d52..0000000 --- a/demo-angular/angular.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "version": 1, - "newProjectRoot": "projects", - "cli": { - "defaultCollection": "@nativescript/schematics" - }, - "projects": { - "blank": { - "root": "", - "sourceRoot": "src", - "projectType": "application", - "prefix": "ns" - } - }, - "defaultProject": "blank" -} \ No newline at end of file diff --git a/demo-angular/package.json b/demo-angular/package.json index b6c1a0c..36163b7 100644 --- a/demo-angular/package.json +++ b/demo-angular/package.json @@ -28,7 +28,8 @@ "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" }, @@ -36,4 +37,4 @@ "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'", "build.plugin": "cd ../src && npm run build" } -} \ No newline at end of file +} diff --git a/demo-angular/src/app/home/home.component.ts b/demo-angular/src/app/home/home.component.ts index 03edeaa..650764f 100644 --- a/demo-angular/src/app/home/home.component.ts +++ b/demo-angular/src/app/home/home.component.ts @@ -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) { diff --git a/demo-vue/app/App_Resources/iOS/Info.plist b/demo-vue/app/App_Resources/iOS/Info.plist index 65b54cd..e9203ca 100644 --- a/demo-vue/app/App_Resources/iOS/Info.plist +++ b/demo-vue/app/App_Resources/iOS/Info.plist @@ -47,5 +47,7 @@ UIStatusBarStyleLightContent UIViewControllerBasedStatusBarAppearance + NSLocationAlwaysAndWhenInUseUsageDescription + Need location always and when in use. diff --git a/demo-vue/app/components/Home.vue b/demo-vue/app/components/Home.vue index 8acc1a7..9caec11 100644 --- a/demo-vue/app/components/Home.vue +++ b/demo-vue/app/components/Home.vue @@ -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) { diff --git a/demo/app/App_Resources/iOS/Info.plist b/demo/app/App_Resources/iOS/Info.plist index ea3e3ea..e96fbed 100644 --- a/demo/app/App_Resources/iOS/Info.plist +++ b/demo/app/App_Resources/iOS/Info.plist @@ -43,5 +43,7 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + NSLocationAlwaysAndWhenInUseUsageDescription + Need location always and when in use. diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index c1afb9d..c1c7d8a 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -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) { diff --git a/src/package.json b/src/package.json index 62b702e..c25a68d 100644 --- a/src/package.json +++ b/src/package.json @@ -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/**'"