简体   繁体   中英

Geofencing events not working on simulator (Xamarin.ios)

I have a problem with firing geofence events on Xamarin.ios . I remember I used to have it working using the same methods in the past. Right now it doesn't work somehow. I'm using the following code to start monitoring:

CLLocationManager locMan = new CLLocationManager();
locMan.RequestWhenInUseAuthorization();
locMan.RequestAlwaysAuthorization();
locMan.RegionEntered += (sender, e) => { Console.WriteLine("You've entered the region"); };

locMan.RegionLeft += (sender, e) => { Console.WriteLine("You've left the region"); };

CLCircularRegion aRegion2 = new CLCircularRegion(new CLLocationCoordinate2D(30.432, 97.7360), 100, "apple test");
locMan.StartMonitoring(aRegion2);

And that's one demo project that I'm trying to test the geofence events on but not working : https://github.com/aproram/Xamarin_ios_geofence_issue_demo

I'm testing the location change from the simulator menu (Debug->locaiton->custom location). Sometimes I get this message in the console output while changing the location:

[Client] #Spi, Interrupted

Development environment:
Visual Studio v8.1
Xamarin.iOS Version: 12.10.0.153
xCode 10.1
Simulator iphone 6s (ios 12.1)

One thing to mention, I tried testing geofencing with an xCode SWIFT project and the events were fired. So I'm not sure if the problem is with my C# code or VS..

stack overflow post

I don't know if this is the issue you are running into, but you need to make sure you have all three of the description keys in your info.plist for anything > iOS 11. That may be why it used to work, but doesn't work now.

The keys are as follows:

NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription

There is a WWDC video talking about the changes in CoreLocation coming in iOS 13 so this may change yet again (I don't remember the details of that offhand). iOS 13 CoreLocation Video

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM