5
5
// - the code between BEGIN USER CODE and END USER CODE
6
6
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7
7
// Other code you write will be lost the next time you deploy the project.
8
- import Geolocation , { GeolocationStatic } from "@react-native-community/geolocation" ;
8
+ import Geolocation , { GeolocationError } from "@react-native-community/geolocation" ;
9
9
10
10
import type { GeolocationServiceStatic , AuthorizationResult } from "../../typings/Geolocation" ;
11
11
@@ -20,11 +20,7 @@ export async function RequestLocationPermission(): Promise<boolean> {
20
20
// BEGIN USER CODE
21
21
22
22
let reactNativeModule : typeof import ( "react-native" ) | undefined ;
23
- let geolocationModule :
24
- | Geolocation
25
- | GeolocationStatic
26
- | typeof import ( "react-native-geolocation-service" )
27
- | undefined ;
23
+ let geolocationModule : typeof import ( "@react-native-community/geolocation" ) . default ;
28
24
29
25
const hasPermissionIOS = async ( ) : Promise < boolean > => {
30
26
const openSetting = ( ) : void => {
@@ -122,13 +118,15 @@ export async function RequestLocationPermission(): Promise<boolean> {
122
118
status => status === reactNativeModule ?. PermissionsAndroid . RESULTS . GRANTED
123
119
)
124
120
) ;
125
- } else if ( geolocationModule && ( geolocationModule as GeolocationStatic ) . requestAuthorization ) {
126
- try {
127
- ( geolocationModule as GeolocationStatic ) . requestAuthorization ( ) ;
128
- return Promise . resolve ( true ) ;
129
- } catch ( error ) {
130
- return Promise . reject ( error ) ;
131
- }
121
+ } else if ( geolocationModule ) {
122
+ geolocationModule . requestAuthorization (
123
+ ( ) => {
124
+ return Promise . resolve ( true ) ;
125
+ } ,
126
+ ( err : GeolocationError ) => {
127
+ return Promise . reject ( err ) ;
128
+ }
129
+ ) ;
132
130
}
133
131
134
132
return false ;
@@ -142,7 +140,7 @@ export async function RequestLocationPermission(): Promise<boolean> {
142
140
}
143
141
144
142
if ( reactNativeModule . NativeModules . RNFusedLocation ) {
145
- geolocationModule = ( await import ( "react-native-geolocation-service " ) ) . default ;
143
+ geolocationModule = ( await import ( "@ react-native-community/ geolocation" ) ) . default ;
146
144
return hasLocationPermission ( ) ;
147
145
} else if ( reactNativeModule . NativeModules . RNCGeolocation ) {
148
146
geolocationModule = Geolocation ;
0 commit comments