2017-07-18 53 views
0

我已經創建了位置跟蹤應用程序。今天我還添加了Geofencing功能。我是簡單的單身人士課程,當地理位置圍繞着cooridnates時引發事件。Xamarin Android - 關於相關問題

當我手動提出事件,然後它按預期工作。但是,當我在座標達到釋放模式時設置停止應用程序。我有錯誤日誌裏面,每一個寫的是: java.lang.reflect.InvocationTargetException

我正在使用MVVMCross庫。我的視圖模型附加到Geofencing服務類女巫回調。當用戶到達cooridnate時,應該調用回調函數。正如我在調試中所說的那樣工作。

下面的代碼示例:

public class GeofenceService : IGeofenceService 
    { 
     //... 
     public event EventHandler<GeofenceStatusChangedEventArgs> StatusChanged; 
     //.. 
    } 


public abstract class GeofenceViewModel : BaseViewModel 
    { 
     protected IGeofenceService GeofenceService { get; } 

     protected virtual void StartMonitoring(AddressModel address, MonitoringRadius radius) 
     { 
      MonitoredAddress = address; 
      GeofenceService.StartMonitoring(new Location(address.Id, address.Latitude, address.Longitude), radius, GeofenceExpectation); 
      GeofenceService.Subscribe(this, OnStatusChanged); 
     } 

protected void OnStatusChanged(object sender, GeofenceStatusChangedEventArgs e) 
     { 
      //... 
     } 
    } 

有沒有一種方法,我怎樣才能得到真正的例外?

回答

1

當然,在你的:應用類的init添加產生的異常委託

AndroidEnvironment.UnhandledExceptionRaiser += (object sender, RaiseThrowableEventArgs e) => { 
    //Save exeption to file (e.Exception.ToString()) 
}; 

但我從我的經驗,我會勸你比較調試和發佈配置(選項)可能有一些設置,那不匹配並導致崩潰。

+0

這行代碼的人保存了很多我的時間。非常感謝 !! – miechooy