Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

getCurrentPosition never calls back when the permission is not yet requested #280

Closed ghost closed 3 years ago

ghost commented 3 years ago

Description

Trying it out on iPhone 12 Simulator, iOS 14.4, when Geolocation.getCurrentPosition is called without having the permission requested yet, neither SuccessCallback, nor ErrorCallback is ever called. I expect ErrorCallback to be called almost immediately with the following error object: {message: "Location permission denied", code: 1}, however, it just does not finish.

It errors out when I pass a timeout value. Otherwise, it doesn't finish at all.

Here's the code:

            Geolocation.getCurrentPosition(
                  (position) => {
                        console.group('Success Callback')
                        console.log(position)
                        console.groupEnd()
                  },
                  (error) => {
                        console.group('Error Callback')
                        console.log(error)
                        console.groupEnd()
                  },

            )

It doesn't finish out when permission is requested and granted too.

import Geolocation from 'react-native-geolocation-service'
import { request, PERMISSIONS } from 'react-native-permissions'

 const onPress = async () => {
            const permission =await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE)
            Geolocation.getCurrentPosition(
                  (position) => {
                        console.group('Success Callback')
                        console.log(position)
                        console.groupEnd()
                  },
                  (error) => {
                        console.group('Error Callback')
                        console.log(error)
                        console.groupEnd()
                  },
            )
      }

Versions

"react": "17.0.1" "react-native-geolocation-service": "^5.3.0-beta.1" "react-native": "0.64.1",

I can confirm that the issue is present for version 5.2.0 as well.

Agontuk commented 3 years ago

It's a known issue, you have to pass timeout for now. I'll rewrite the ios code soon, hopefully it'll be fixed then.

Related #244