2017-01-27 7 views
1

Wenn ich die CLLocationManager-Instanz nur auf UIThread erstelle, wird das LocationUpdated-Ereignis ausgelöst. Warum passiert das? Es gibt keine Hinweise in der Dokumentation von Xamarin und Apple, dass CLLocationManager created auf UIThread sein muss.Warum liefert CLLocationManager keine zu bearbeitenden Ereignisse?

Einige Code fragt locationManager.RequestWhenInUseAuthorization(); NSLocationWhenInUseUsageDescription wird gefassten in Info.plist

private void CreateLocationManagerWorkingOption() { 
    ExecuteOnMainThread (() => { 
     locationManager = new CLLocationManager(); 
    }); 
    locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { 
     OnLocationChanged (locationManager,e.Locations [e.Locations.Length - 1]); 
    }; 
} 

private void CreateLocationManagerNotWorkingOption() { 
    ExecuteOnSomeThread(()=> { 
     locationManager = new CLLocationManager(); 
    }); 
    locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { 
     OnLocationChanged (locationManager,e.Locations [e.Locations.Length - 1]); 
    }; 
} 

private void StartTrackingImpl() { 
    ExecuteOnMainThread (() => locationManager?.StartUpdatingLocation()); 
} 

Antwort

0

Sie können erstellen und zu handhaben es aus jedem Thread, der eine aktive Laufschleife aufweist.

Vom CLLocationManagerDelegate documentation:

Die Methoden des Delegatobjekt aus dem Thread aufgerufen werden, in dem Sie die entsprechenden Standort-Dienste gestartet. Dieser Thread muss selbst eine aktive Ausführungsschleife haben, wie sie im Hauptthread Ihrer Anwendung zu finden ist.

+0

Sie wirkt sich nur auf StartUpdatingLocation und andere Aktualisierungsmethoden aus. Es gibt keine Informationen zum Konstruktor. Außerdem habe ich Xamarin-Dokumentation gemeint, weil mono den CLLoationManager beeinflussen kann. – Alexander

Verwandte Themen