Open josh-gree opened 3 years ago
@byCedric FYI - if I use the QR from (https://staging.expo.dev/@bycedrictest/office-marathon - which I found in the logcat output for the app store app it works)
Needs cleaning up some UI nastyness - but it works in terms of permissions etc
diff --git a/app.json b/app.json
index e0f477e..2a39e9f 100644
--- a/app.json
+++ b/app.json
@@ -28,8 +28,7 @@
"package": "com.bycedric.officemarathon",
"permissions": [
"ACCESS_COARSE_LOCATION",
- "ACCESS_FINE_LOCATION",
- "ACCESS_BACKGROUND_LOCATION"
+ "ACCESS_FINE_LOCATION"
]
},
"web": {
diff --git a/src/screens/onboarding.tsx b/src/screens/onboarding.tsx
index 78f56fe..e0f09c9 100644
--- a/src/screens/onboarding.tsx
+++ b/src/screens/onboarding.tsx
@@ -1,38 +1,12 @@
import { useNavigation } from '@react-navigation/native';
-import * as Location from 'expo-location';
-import React, { useCallback, useEffect, useState } from 'react';
-import { View } from 'react-native';
+import { LOCATION_FOREGROUND, usePermissions } from 'expo-permissions';
+import React, { useCallback, useEffect } from 'react';
import { Box, Button, Spinner, Title, Paragraph } from '../providers/theme';
-
-const getfg = async (setfg) => {
- let { status } = await Location.requestForegroundPermissionsAsync();
- console.log(`FG PERMISSIONS -> ${status}`);
- if (status === "granted") {
- console.log(`SETTING STATE -> ${true}`);
- setfg(true);
- } else {
- console.log("FG PERMISSIONS DENIED");
- }
-};
-
-const getbg = async (setbg) => {
- let { status } = await Location.requestBackgroundPermissionsAsync();
- console.log(`BG PERMISSIONS -> ${status}`);
-
- if (status === "granted") {
- console.log(`SETTING STATE -> ${true}`);
- setbg(true);
- } else {
- console.log("BG PERMISSIONS DENIED");
- }
-};
-
export const OnboardingScreen: React.FC = () => {
const navigation = useNavigation();
- const [fg_permission, setfg] = useState(false)
- const [bg_permission, setbg] = useState(false)
+ const [permission, askPermission] = usePermissions(LOCATION_FOREGROUND);
const onContinue = useCallback(() => {
navigation.navigate('Distance');
@@ -41,12 +15,12 @@ export const OnboardingScreen: React.FC = () => {
useEffect(() => {
// Only redirect on first render or permission change,
// not when users go back to this screen.
- if (fg_permission && bg_permission) {
+ if (permission?.granted) {
onContinue();
}
- }, [fg_permission,bg_permission]);
+ }, [permission?.granted]);
- if (fg_permission && bg_permission) {
+ if (permission?.granted) {
return (
<Box variant='page'>
<Box>
@@ -64,12 +38,9 @@ export const OnboardingScreen: React.FC = () => {
<Title>We need your permission</Title>
<Paragraph>To monitor your office marathon, we need access to your location.</Paragraph>
</Box>
- {!(fg_permission && bg_permission)
- ? <View>
- <Button onPress={() => getfg(setfg)}>Grant permission FG</Button>
- <Button onPress={() => getbg(setbg)}>Grant permission BG</Button>
- </View> : null
-
+ {!permission
+ ? <Spinner />
+ : <Button onPress={askPermission}>Grant permission</Button>
}
</Box>
);
ACCESS_BACKGROUND_LOCATION
Location.requestForegroundPermissionsAsync
+ Location.requestBackgroundPermissionsAsync
NB: It doesn't actually work anymore with the above changes :-( - This is exactly the issue I have faced in my own development and it is soooo annoying I wish someone from expo could help! The background work now never happens - the app starts the correct permission dialogues come up - settings shows the app has always for location permission - while the app is open there is a push notification saying locations are being collected - as soon as the app is closed the notification goes away - do I need to go back to an older version of the expo sdk? I am using 4.10.1
- this clearly works somehow (since the app store version does) but as it stands I am at my wits end getting background locations to work!
Description of the bug
Unable to get the app to work via expoGo
To Reproduce
Expected behavior
Not to get errors
Actual behavior
Permission screen only asks for foreground permissions then moves to the tracking screen - but gets
Not authorized to use background location services.
on pressAdditional context
Have also downloaded from app store and it does seem to work there - what commit is the app store version associated to?