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

Errors running in expo Go - seems to work for the version in the app store #14

Open
josh-gree opened this issue Aug 25, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@josh-gree
Copy link

Description of the bug

Unable to get the app to work via expoGo

To Reproduce

npm install
expo start

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 press

Android Bundling complete 87ms
Android Running app on POT-LX1

expo-permissions is now deprecated — the functionality has been moved to other expo packages that directly use these permissions (e.g. expo-location, expo-camera). The package will be removed in the upcoming releases.
at node_modules/expo-permissions/build/Permissions.js:42:4 in getAsync
at node_modules/expo-permissions/build/Permissions.js:41:7 in getAsync
at node_modules/expo-permissions/build/PermissionsHooks.js:32:45 in useCallback$argument_0
at node_modules/expo-permissions/build/PermissionsHooks.js:42:26 in useEffect$argument_0

expo-permissions is now deprecated — the functionality has been moved to other expo packages that directly use these permissions (e.g. expo-location, expo-camera). The package will be removed in the upcoming releases.
at node_modules/expo-permissions/build/Permissions.js:49:4 in askAsync
at node_modules/expo-permissions/build/Permissions.js:48:7 in askAsync
at node_modules/expo-permissions/build/PermissionsHooks.js:27:45 in useCallback$argument_0
at node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
at node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
at node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease

[Unhandled promise rejection: Error: Not authorized to use background location services.]
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-location/build/Location.js:172:11 in hasStartedLocationUpdatesAsync
at node_modules/expo-location/build/Location.js:170:7 in hasStartedLocationUpdatesAsync
at src/services/location/track.ts:16:15 in isTracking
at src/services/location/track.ts:15:7 in isTracking
at src/services/location/index.ts:58:4 in useEffect$argument_0

Additional context

Have also downloaded from app store and it does seem to work there - what commit is the app store version associated to?

@josh-gree josh-gree added the bug Something isn't working label Aug 25, 2021
@josh-gree
Copy link
Author

@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)

@josh-gree
Copy link
Author

josh-gree commented Aug 25, 2021

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>
   );
  • Added ACCESS_BACKGROUND_LOCATION
  • Use the two location permission methods Location.requestForegroundPermissionsAsync + Location.requestBackgroundPermissionsAsync

@josh-gree
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant