2014-07-09 3 views
2

나는 위도와 경도로 사용자 위치를 취한 다음 API를 사용하여 결과를 돌려주는 날씨 앱을 가지고 있습니다. 위치 서비스가 꺼지면 앱이 열렸을 때 충돌이 발생하고 오류가 발생한 곳을 알 수있는 오류 도움말이 표시되지 않습니다. 위치 서비스가 하나인지 확인하기 위해 if 문을 작성하는 방법이 있습니까? 이 문제를 방지하려면 어떻게해야합니까? - https://dev.windowsphone.com/en-US/CrashReport ( 위치 서비스가 꺼져있을 때 Windows 8 전화 앱이 열렸을 때 오류가 발생합니다.

async private void GetLocation() 
     { 
      var geolocator = new Geolocator(); 
      if (geolocator.LocationStatus == PositionStatus.Disabled) 
      { 
       //MessageBox.Show("We need your current location for the app to function properly, please set location services on in settings"); 
       MessageBoxResult mRes = MessageBox.Show("We need your current location for the app to function properly, please set location services on in settings", "I understand", MessageBoxButton.OKCancel); 
       if (mRes == MessageBoxResult.OK) 
       { 
        Application.Current.Terminate(); 
       } 
       if (mRes == MessageBoxResult.Cancel) 
       { 
        Application.Current.Terminate(); 
       } 
      } 

      Geoposition position = await geolocator.GetGeopositionAsync(); 
      Geocoordinate coordinate = position.Coordinate; 
      latitude = Convert.ToString(Math.Round(coordinate.Latitude, 2)); 
      longitude = Convert.ToString(Math.Round(coordinate.Longitude, 2)); 

      URL = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&units=metric"; 

      Client(URL); 
     } 

public void Client(string uri) 
     { 
      var clientToken = new WebClient(); 
      clientToken.OpenReadCompleted += clientToken_OpenReadCompleted; 
      clientToken.OpenReadAsync(new Uri(uri)); 
     } 

오류가 Windows 개발자 센터에서 마이크로 소프트에 의해 기록 당신의 오류 스택 추적을 확인 발생하는 위치를

답변

0

결정하기 위해 어떤 도움 :) 주셔서 감사합니다 : 여기

코드입니다 그래프 위의 "지난 30 일 동안의 상위 스택 추적 내보내기"링크).

표시되는 스택 추적에 지연이있을 수 있습니다. BugSense은 디버깅에 도움이되는 큰 오류 보고서를 제공하는 매우 유용한 도구입니다. 처리되지 않은 예외를 잡기 위해 한 줄의 코드 만 앱에서 실행됩니다.

BugSense에서 오류 보고서에 추가되는 "breadcrumbs"를 추가 할 수도 있습니다. 그런 다음 위치에서 서비스가 실행되고 있음을 확인하고이 정보를 추가하면 예외 스택 추적에서 문제를 파악하는 데 도움이됩니다.

0

문제는 위치가 꺼져있을 때, 그것은 block.Here 제대로이 처리하는 MSDN에서 샘플 코드 당신이 시도/캐치에 처리되지 않은 예외가 발생한다는 것입니다 :

private async void OneShotLocation_Click(object sender, RoutedEventArgs e) 
{ 

    if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true) 
    { 
     // The user has opted out of Location. 
     return; 
    } 

    Geolocator geolocator = new Geolocator(); 
    geolocator.DesiredAccuracyInMeters = 50; 

    try 
    { 
     Geoposition geoposition = await geolocator.GetGeopositionAsync(
      maximumAge: TimeSpan.FromMinutes(5), 
      timeout: TimeSpan.FromSeconds(10) 
      ); 

     LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00"); 
     LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00"); 
    } 
    catch (Exception ex) 
    { 
     if ((uint)ex.HResult == 0x80004004) 
     { 
      // the application does not have the right capability or the location master switch is off 
      StatusTextBlock.Text = "location is disabled in phone settings."; 
     } 
     //else 
     { 
      // something else happened acquring the location 
     } 
    } 
} 

당신에게 더 나은 이해를 위해 Source MSDN 문서를 방문하여 읽어야합니다. 이 샘플은 7 단계에 있습니다.

관련 문제