2016-10-06 13 views
0

여기에는 React Native에서 geolocation 서비스를 비동기 적으로 호출하는 함수 geolocate()이 있습니다.React Native의 예외 전파

geolocationError() 안에 오류가 발생하면 geolocate() 부모에게 전파되지 않지만 빨간색 오류 화면이 나타납니다.

catch() 블록에 오류를 전파하는 방법은 geolocate()입니까? Promise.reject()

async geolocate() { 
    try { 
     let result = await navigator.geolocation.getCurrentPosition(
     this.geolocationSuccess.bind(this), 
     this.geolocationError.bind(this), 
     {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000} 
    ); 
     if (result != null) return result; 
    } catch(err) { 
     // This doesn't get called 
     Alert.alert(
     "Location unknown", 
     "Turn localization services on.", 
     [ 
      {text: 'OK', onPress:() => console.log('OK')}, 
     ] 
    ); 
    }; 
    } 

    geolocationError(err) { 
    console.log(err); 
    throw err; // Stops here -> Promise.reject() does better job here, but still results in "Unhandled promise rejection" 
    } 

답변

0

트릭을 할 것 같다,하지만, 난 여전히 처리되지 않은 약속 제거를 얻을.

[warn][tid:com.facebook.react.JavaScript] Possible Unhandled Promise Rejection (id: 0): 
Location services disabled. 
관련 문제