2017-07-18 75 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