Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on IOS #190

Closed
1 of 2 tasks
tzvc opened this issue Feb 14, 2019 · 22 comments
Closed
1 of 2 tasks

Exception on IOS #190

tzvc opened this issue Feb 14, 2019 · 22 comments
Labels
platform: ios Issue is related to the iOS platform type: bug Something isn't working up for graps Issues marked with this label are relatively easy problems that are ideal for starting contributors.

Comments

@tzvc
Copy link

tzvc commented Feb 14, 2019

🐛 Bug Report

I'm using the stream feature for real time location updates and I ran into an issue. When my position is fixed in the simulator, the update works normally but when I set the location to moving (simulator->debug->location->city run), an exception is thrown:

[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Expected behavior

The location updates without throwing an exception

Reproduction steps


var locationOptions =
      LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

geolocator.getPositionStream(locationOptions).listen((Position position) {
      print("New pos update: $position");
      if (position != null)
        setState(() {
          _position = position;
        });
    });

Configuration

Version: 2.1.1

Platform:

  • 📱 iOS
  • 🤖 Android
@nicolasjon
Copy link

nicolasjon commented Feb 19, 2019

I have a similar issue - Using the stream for real time location updates and I ran into an issue. When my position is fixed in the simulator, the update works normally. Update the position from debug/location a couple of times and this error occurs

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)

Config
Using geolocator: "3.0.0"

iOS Simulator (12.1) and device (12.1.4)

I am investigating this further, will update soon.

@nicolasjon
Copy link

Works correctly on iOS simulator 10.1, 11.1
using - simulator->debug->location->freeway drive

Fails on 12.1
using - simulator->debug->location->freeway drive
PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed.

@nicolasjon
Copy link

geolocator example Fails on 12.1

screenshot 2019-02-19 at 14 28 04

@barthr
Copy link

barthr commented Mar 3, 2019

I'm having the same problem

@dxps
Copy link

dxps commented Mar 5, 2019

True. It happens even with the provided example.

@FlashJonas
Copy link

FlashJonas commented Mar 7, 2019

Hi, I am seeing the same issue, but for me I tried "city bicycle ride" first, and that worked! But then it failed when switching over to "city run" with this error.

So City Bicycle Ride might be a profile you can use in the meantime.

Edit 1: And now bicycle mode stopped working as well!
Edit 2: Uninstalling the app, and re-allowing location access fixed this issue for me.

@andyvanosdale
Copy link

I'm seeing this as well. I did this as a work around:

  StreamSubscription<Position> _positionStream;

  void _streamLocation() {
    // TODO: initialize _positionStream
    _positionStream.onError((e) {
      print("error streaming position: $e");
      _disposePositionStream();
      _streamLocation();
    });
  }

  void _disposePositionStream() {
    if (_positionStream != null) {
      _positionStream.cancel();
      _positionStream = null;
    }
  }

Restarting the stream seems to make it work now.

NOTE: This is not the optimal way to handle this with nulling the _positionStream while it is still being used by onError.

@nicolasjon
Copy link

Still getting this error using the example app
Single seems to work, although occasionally reports null, stream fails after a few updates.

PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)

Config (Now)
Using geolocator: "5.1.1+1"

iOS Simulator (12.4) and device (10.x.x)

@nicolasjon
Copy link

By way of a Hack test..

LocationTask.m

  • (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"%s", sel_getName(_cmd));
    // [[self context] resultHandler]([FlutterError errorWithCode:@"*ERROR_UPDATING_LOCATION" message:error.localizedDescription details:nil]);
    [self stopTask];
    [self startTask]; // Forgive me...
    }

This works reliably on the Simulator 12.4 and 10.3
Remember the simulator Debug, Location sometimes has to be kicked a few times before it changes.

Thoughts?

@VladimirCourse
Copy link

Having the same problem after updating library to latest version. After some tests we found that exceptions kicked when WiFi is on, if enable 3g it works correcty. Any solutions for this?

@StijnWoerkom StijnWoerkom added platform: ios Issue is related to the iOS platform type: bug Something isn't working up for graps Issues marked with this label are relatively easy problems that are ideal for starting contributors. labels Sep 20, 2019
@Abdullah2050
Copy link

Abdullah2050 commented Oct 3, 2019

Having a similar problem. I'm trying to complete a course from londonappbrewery. I'm getting the following exceptions! Don't know how to fix it :/

Code:
Screenshot 2019-10-03 at 9 55 17 PM

As I press the button it shows:

Launching lib/main.dart on iPhone Xʀ in debug mode...
Running Xcode build...
Xcode build done. 24.1s
Syncing files to device iPhone Xʀ...
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)

#2 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:103:32)

#3 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:12:10)

#4 _LoadingScreenState.build. (package:clima/screens/loading_screen.dart:22:13)
#5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
#6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32)
#7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#8 <…>

I've also tried to run it on the android simulator (Pixel 3a API 28). It worked but unfortunately, it's providing incorrect coordinates. The difference in coordinates is huge. Like, I'm trying to get a location from Pakistan and its showing location somewhere in the USA.

@StijnWoerkom
Copy link
Contributor

StijnWoerkom commented Oct 11, 2019

#252 take a look at this and see if you have problems in common. Could you also provide me with some information about the course so I know what I'm looking at?

@esenmx
Copy link

esenmx commented Oct 17, 2019

I faced same issue, my solution is:
Debug -> Location ->

Screen Shot 2019-10-17 at 4 28 02 PM

When I checked here, neither 'None' nor 'Custom Location' were selected, I selected an option as you see and it worked.

@nuzelac
Copy link

nuzelac commented Nov 4, 2019

Also seeing this for iOS devices in production on Sentry. I'm not using realtime location updates, just calls to getCurrentPosition/getLastKnownPosition

PlatformException: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
  File "message_codecs.dart", line 569, in StandardMethodCodec.decodeEnvelope
  File "framework.dart", line 3919, in ComponentElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 2904, in Element.updateChild
  File "framework.dart", line 5127, in SingleChildRenderObjectElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 2904, in Element.updateChild
  File "framework.dart", line 3961, in ComponentElement.performRebuild
  File "framework.dart", line 3738, in Element.rebuild
  File "framework.dart", line 3924, in ComponentElement._firstBuild
  File "framework.dart", line 4088, in StatefulElement._firstBuild
  File "framework.dart", line 3919, in ComponentElement.mount
.
.
.

Ideas?

@ggeldenhuis
Copy link

ggeldenhuis commented Jan 2, 2020

The following code creates the same error for me:

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

class LoadingScreen extends StatefulWidget {
  @override
  _LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> {

  void getLocation() async {
    Position position = await Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    print(position);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            getLocation();
          },
          child: Text('Get Location'),
        ),
      ),
    );
  }
}

Versions

Android Studio 3.5.3
Build #AI-191.8026.42.35.6010548, built on November 15, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.2

geolocator-5.1.5
location_permissions-2.0.3
flutter version: v1.13.5

Running on similator: Iphone 11 Pro Max 13.3

As suggested by @softronaut setting the location in the simulator app will get rid of the error. So perhaps an improved error message would help. In my case the error was because no location was set.

@TUKenStone
Copy link

Having a similar problem. I'm trying to complete a course from londonappbrewery. I'm getting the following exceptions! Don't know how to fix it :/

Code:
Screenshot 2019-10-03 at 9 55 17 PM

As I press the button it shows:

Launching lib/main.dart on iPhone Xʀ in debug mode...
Running Xcode build...
Xcode build done. 24.1s
Syncing files to device iPhone Xʀ...
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)

#2 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:103:32)

#3 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:12:10)

#4 _LoadingScreenState.build. (package:clima/screens/loading_screen.dart:22:13)
#5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
#6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32)
#7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#8 <…>

I've also tried to run it on the android simulator (Pixel 3a API 28). It worked but unfortunately, it's providing incorrect coordinates. The difference in coordinates is huge. Like, I'm trying to get a location from Pakistan and its showing location somewhere in the USA.

fixed it by following the iOS Simulator -> Features -> Location -> Custom Location...

@pparikhatliaison
Copy link

You have to set you custom location on the simulator under features>location>custom location

@nathanogunleye
Copy link

I faced same issue, my solution is:
Debug -> Location ->

Screen Shot 2019-10-17 at 4 28 02 PM

When I checked here, neither 'None' nor 'Custom Location' were selected, I selected an option as you see and it worked.

I've had to set this option a couple of times now. For some reason every now and again the setting resets itself. Anyone know why this is?

@darbyo
Copy link

darbyo commented Jul 21, 2020

Updated, this is now in Features -> Location -> Select an option

@mvanbeusekom
Copy link
Member

Solved in version 6.0.0

@martin-braun
Copy link

martin-braun commented May 1, 2022

@mvanbeusekom Obviously, this issue still appears when no location is set in the iPhone Simulator as others have pointed out. This is alright, but how to catch it properly?

try {
  permissionGranted = await location.requestPermission();
  if (permissionGranted == LocationPlatformInterface.PermissionStatus.granted) {
    currentPosition = await Geolocator.getCurrentPosition(
      desiredAccuracy: desiredAccuracy ?? LocationAccuracy.best
    ); // crash, but no exception
  } else {
    currentPosition = null;
  }
} catch (e) {
  print(e);
  currentPosition = null;
}

This code will not catch the issue and it's hard to pin-point, as the message only appears in the Xcode logs. Also further execution will not work, see my referenced issue above. I wish it would just raise an exception so I could handle it properly.

Also, do you know if this issue can occur on real devices if I check for permissions? I'm concerned.

Thanks in advance.

@obsoft23
Copy link

obsoft23 commented Feb 21, 2024

Geolocator.getPositionStream().listen((Position position) {
      _currentPosition = position;
 }, onError: (error) {
      print('Error receiving location update: $error');
});

//Adding onError fixed it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: ios Issue is related to the iOS platform type: bug Something isn't working up for graps Issues marked with this label are relatively easy problems that are ideal for starting contributors.
Projects
None yet
Development

No branches or pull requests