Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup PR#97 #216

Closed
wants to merge 1 commit into from
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
79 changes: 74 additions & 5 deletions app/services/LocationService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { GetStoreData, SetStoreData } from '../helpers/General';
import BackgroundGeolocation from '@mauron85/react-native-background-geolocation';
import { Alert, Platform } from 'react-native';

import { Alert, Platform, Linking } from 'react-native';
import { PERMISSIONS, check, RESULTS, request } from 'react-native-permissions';
import PushNotificationIOS from '@react-native-community/push-notification-ios';

import PushNotification from 'react-native-push-notification';

let instanceCount = 0;
Expand Down Expand Up @@ -250,6 +249,69 @@ export default class LocationServices {

BackgroundGeolocation.start(); //triggers start on start event

if (Platform.OS === 'ios') {
check(PERMISSIONS.IOS.LOCATION_ALWAYS) // Use react-native-permissions to check for 'Always Allow' permission
.then(result => {
switch (result) {
case RESULTS.UNAVAILABLE:
console.log('Feature not available');
break;
case RESULTS.DENIED:
request(PERMISSIONS.IOS.LOCATION_ALWAYS).then(locRes => {
const majorVersionIOS = parseInt(Platform.Version, 10);
if (locRes === 'granted' && majorVersionIOS >= 13) {
console.log(
'[INFO]',
'While using access granted. iOS version 13+',
);
Linking.openURL('app-settings:'); // Redirect to App Settings if iPhone is iOS 13+
}
});
break;
case RESULTS.GRANTED:
console.log('Access Granted');
BackgroundGeolocation.start();
break;
case RESULTS.BLOCKED:
console.log(
'The permission has been rejected. Cannot request again',
);
break;
}
})
.catch(error => {
console.log('[ERROR]', error);
});
} else {
check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION)
.then(result => {
switch (result) {
case RESULTS.UNAVAILABLE:
console.log('Feature not available android');
break;
case RESULTS.DENIED:
request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION).then(
_locRes => {
console.log('[INFO]', 'Requested permission');
},
);
break;
case RESULTS.GRANTED:
BackgroundGeolocation.start();
console.log('Access Granted');
break;
case RESULTS.BLOCKED:
console.log(
'The permission has been rejected. Cannot request again',
);
break;
}
})
.catch(err => {
console.log('[ERROR]', err);
});
}

if (!status.locationServicesEnabled) {
// we need to set delay or otherwise alert may not be shown
setTimeout(
Expand All @@ -260,7 +322,14 @@ export default class LocationServices {
[
{
text: 'Yes',
onPress: () => BackgroundGeolocation.showLocationSettings(),
onPress: () => {
if (Platform.OS === 'android') {
// showLocationSettings() only works for android
BackgroundGeolocation.showLocationSettings();
} else {
Linking.openURL('App-Prefs:Privacy'); // Deeplinking method for iOS
}
},
},
{
text: 'No',
Expand Down Expand Up @@ -292,7 +361,7 @@ export default class LocationServices {
),
1000,
);
}
}
// else if (!status.isRunning) {
// } // commented as it was not being used
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react-native-extended-stylesheet": "^0.12.0",
"react-native-fs": "^2.16.6",
"react-native-gesture-handler": "~1.5.0",
"react-native-permissions": "^2.0.10",
"react-native-i18n": "^2.0.15",
"react-native-map-clustering": "^3.1.2",
"react-native-maps": "0.27.1",
Expand Down