-
Notifications
You must be signed in to change notification settings - Fork 283
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
Add missing notifications for Location Services #64
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
SetStoreData | ||
} from '../helpers/General'; | ||
import BackgroundGeolocation from '@mauron85/react-native-background-geolocation'; | ||
import { Alert } from 'react-native'; | ||
|
||
var instanceCount = 0; | ||
var lastPointCount = 0; | ||
|
@@ -64,17 +65,17 @@ export default class LocationServices { | |
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY, | ||
stationaryRadius: 50, | ||
distanceFilter: 50, | ||
notificationTitle: 'PrivateKit Enabled', | ||
notificationText: 'PrivateKit is recording path information on this device.', | ||
notificationTitle: 'Private Kit Enabled', | ||
notificationText: 'Private Kit is securely storing your GPS coordinates once every five minutes on this device.', | ||
debug: false, // when true, it beeps every time a loc is read | ||
startOnBoot: false, | ||
stopOnTerminate: false, | ||
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER, | ||
|
||
// DEBUG: Use these to get a faster output | ||
// interval: 2000, | ||
// fastestInterval: 2000, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes | ||
// activitiesInterval: 2000, | ||
/*interval: 2000, | ||
fastestInterval: 2000, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes | ||
activitiesInterval: 2000,*/ | ||
|
||
interval: 20000, | ||
fastestInterval: 60000 * 5, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes | ||
|
@@ -120,7 +121,7 @@ export default class LocationServices { | |
BackgroundGeolocation.on('stationary', (stationaryLocation) => { | ||
// handle stationary locations here | ||
// Actions.sendLocation(stationaryLocation); | ||
BackgroundGeolocation.startTask(taskKey => { | ||
BackgroundGeolocation.startTask(taskKey => { | ||
// execute long running task | ||
// eg. ajax post location | ||
// IMPORTANT: task has to be ended by endTask | ||
|
@@ -144,10 +145,11 @@ export default class LocationServices { | |
|
||
BackgroundGeolocation.on('authorization', (status) => { | ||
console.log('[INFO] BackgroundGeolocation authorization status: ' + status); | ||
|
||
if (status !== BackgroundGeolocation.AUTHORIZED) { | ||
// we need to set delay or otherwise alert may not be shown | ||
setTimeout(() => | ||
Alert.alert('App requires location tracking permission', 'Would you like to open app settings?', [{ | ||
Alert.alert('Private Kit requires access to location information', 'Would you like to open app settings?', [{ | ||
text: 'Yes', | ||
onPress: () => BackgroundGeolocation.showAppSettings() | ||
}, | ||
|
@@ -158,6 +160,12 @@ export default class LocationServices { | |
} | ||
]), 1000); | ||
} | ||
else { | ||
BackgroundGeolocation.start(); //triggers start on start event | ||
|
||
// TODO: We reach this point on Android when location services are toggled off/on. | ||
// When this fires, check if they are off and show a Notification in the tray | ||
} | ||
}); | ||
|
||
BackgroundGeolocation.on('background', () => { | ||
|
@@ -195,10 +203,39 @@ export default class LocationServices { | |
console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled); | ||
console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization); | ||
|
||
// you don't need to check status before start (this is just the example) | ||
if (!status.isRunning) { | ||
BackgroundGeolocation.start(); //triggers start on start event | ||
BackgroundGeolocation.start(); //triggers start on start event | ||
|
||
if (!status.locationServicesEnabled) { | ||
// we need to set delay or otherwise alert may not be shown | ||
setTimeout(() => | ||
Alert.alert('Private Kit requires location services to be enabled', 'Would you like to open location settings?', [{ | ||
text: 'Yes', | ||
onPress: () => BackgroundGeolocation.showLocationSettings() | ||
}, | ||
{ | ||
text: 'No', | ||
onPress: () => console.log('No Pressed'), | ||
style: 'cancel' | ||
} | ||
]), 1000); | ||
} | ||
else if (!status.authorization) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I don't authorize and press Yes for settings, then I end up at App settings which doesn't have location information anywhere. |
||
// we need to set delay or otherwise alert may not be shown | ||
setTimeout(() => | ||
Alert.alert('Private Kit requires access to location information', 'Would you like to open app settings?', [{ | ||
text: 'Yes', | ||
onPress: () => BackgroundGeolocation.showAppSettings() | ||
}, | ||
{ | ||
text: 'No', | ||
onPress: () => console.log('No Pressed'), | ||
style: 'cancel' | ||
} | ||
]), 1000); | ||
} | ||
else if (!status.isRunning) { | ||
} | ||
|
||
}); | ||
|
||
// you can also just start without checking for status | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might not say securely storing as we are not encrypting the coordinates, they are stored in raw format. However, no other app can access it so it is good as well.