Skonfiguruj zestaw lokalizacji huawei do ustalania lokalizacji urządzenia w godzinach nadliczbowych, gdy są używane aplikacje, wykonaj konfigurację z https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/config-agc-0000001050197382-V1
u nas nie ma rzeczywistego urządzenia huawei, korzystamy z chmury debugowanie
Spróbuj zrealizować, aby obserwować lokalizację gps w godzinach nadliczbowych z tym wszystkim składnią
// ------ Parent ------
// this put on the parent useEffect
HMSLocation.LocationKit.Native.init()
.then(() => console.log('----------Success Initialize----------'))
.catch((err) => alert(err.message))
// ------ Child ------
const stopWatchingLocation = () => {
if (hasHms) {
HMSLocation.FusedLocation.Events.removeFusedLocationEventListener(
(res: LocationResult) => console.log('remove add listener', res),
)
}
}
const startWatchingLocation = async () => {
if (hasHms) {
HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallbackEx(
hwGeolocationOptions,
)
.then((res) => console.log('success request', res))
.catch((error) => console.log('failed request', error))
HMSLocation.FusedLocation.Events.addFusedLocationEventListener(
(res: LocationResult) => console.log('result', res.lastHWLocation)
)
}
}
// implementation of add & remove event listener
useEffect(() => {
startWatchingLocation() // inside here invoke addFusedLocationEventListener
return stopWatchingLocation // inside here invoke, cleanup function removeFusedLocationEventListener
}, [])
Kod pomyślnie powoduje init
, requestLocationUpdatesWithCallbackEx
ale wejście do konsoli z addFusedLocationEventListener
nigdy nie zasłaniaj
Już włącz rozdzielczość hms core app dla lokalizacji, hasPermission
również zwrócona wartość true
Próbowałem locationRequest
rozwiązania problemu z komentarzami react native @hmscore/react-native-hms-lokalizacja, nadal nie działa
Jak możemy to naprawić??
removeFusedLocationEventListener
nie raz poaddFusedLocationEventListener
, stawiamyremoveFusedLocationEventListener
wewnątrz funkcji czyszczenia useEffect, nawet gdy usuwamyremoveFusedLocationEventListener
nie powodujeaddFusedLocationEventListener
oddzwonienie też