GetPositionAsync works in android but not in IOS 11

MonkeyD.LuffyMonkeyD.Luffy USMember
 System.Threading.Tasks.TaskCanceledException: A task was canceled.

2017-11-05 14:46:31.228 Byte_Rate.iOS[36807:4480015] 
Unhandled Exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter`

I am having hard time in handling the exception thrown by the following code when i try to debug on ios.11 emulator but this code works fine in android.

private async Task<Plugin.Geolocator.Abstractions.Position> GetPositionAsync() {
            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;
            TimeSpan ts = new TimeSpan((Int32)10000);
            _position = await locator.GetPositionAsync(timeout: ts);
            return _position;
        } 

I have followed all the instructions mentioned in various web sights related to @jamesmontemagno /Xamarin.Plugins/Geolocator/ but no luck. I have made sure my info.plist consist of following code:

              <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
              <string>This app needs access location when open and in the background.</string>
              <key>NSLocationAlwaysUsageDescription</key>
              <string>Need location for geolocator plugin.</string>
              <key>RequestWhenInUseAuthorization</key>
              <string>Need location for geolocator plugin.</string>
              <key>NSLocationWhenInUseUsageDescription</key>
              <string>Need location for geolocator plugin.</string> 

All i am trying to achieve is getting current location on all three platforms (IOS, Android, Windows) with current location. Android is working perfectly but IOS is where i got stuck. Any type of help is appreciated.

Sign In or Register to comment.