Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

requestPermissions fails after checkPermissionStatus is called on iOS #7

Closed
1 of 2 tasks
1rgs opened this issue Apr 30, 2019 · 4 comments
Closed
1 of 2 tasks

Comments

@1rgs
Copy link

1rgs commented Apr 30, 2019

🐛 Bug Report

If requestPermissions is called, this exception is thrown:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_ALREADY_REQUESTING_PERMISSION, A request for permissions is already running, please wait for it to finish before doing another request., null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302)
<asynchronous suspension>
#2      LocationPermissions.requestPermissions (package:location_permissions/src/location_permissions.dart:70)
<asynchronous suspension>
#3      LocationRequest._requestPerms (package:social_dating/location_request.dart:15)
<asynchronous suspension>
#4      LocationRequest.build.<anonymous closure> (package:social_dating/location_request.dart:51)
#5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511)
#6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566)
#7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166)
#8      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240)
#9      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177)
#10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436)
#11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73)
#12     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101)
#13     _RenderingFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221)
#14     _RenderingFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199)
#15     _RenderingFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156)
#16     _RenderingFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102)
#17     _RenderingFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86)
#18     _rootRunUnary (dart:async/zone.dart:1136)
#19     _CustomZone.runUnary (dart:async/zone.dart:1029)
#20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931)
#21     _invoke1 (dart:ui/hooks.dart:233)
#22     _dispatchPointerDataPacket (dart:ui/hooks.dart:154)

Expected behavior

This should work with no exception.

Reproduction steps

  • First call await checkPermissionStatus
  • Then call await requestPermissions

Version: 2.0.0

Platform:

  • 📱 iOS
  • 🤖 Android
@mvanbeusekom
Copy link
Member

@rahulgs12 this exception explains that you have an active request for permissions when a second call to the requestPermissions is coming in. Make sure you await the call to requestPermissions (which you indicate you do) and that you call it only once.

A common mistake is that people call the requestPermissions method from build method in there widget. In some situations this method can be called multiple times by Flutter to organize the UI and in this case also calling the plug-in multiple times.

If you keep on having problems please feel free to send us a code example, even better would be a small app that shows how to reproduce the error and we will be glad to have a look at it.

@Viktoru
Copy link

Viktoru commented Jul 30, 2019

Hello @mvanbeusekom

Thank you for your response. Please, anyone, I need help with this simple geolocation app. It is very simple but I'm having the same problem in ios. It's Working in Android.
dependencies:
location: ^2.3.5
provider: ^3.0.0+1
geolocator: ^5.1.1+1

info.plist file
NSLocationAlwaysUsageDescription
This app needs access to location when in the background.
NSLocationAlwaysAndWhenInUseUsageDescription
This app needs access to location when open and in the background.

==============
main.dart file

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Get User Location',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Get User Location'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {

Position position = null;

void requestLocationPermission(BuildContext context) async {
Position currentPosition = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

setState(() {
  position = currentPosition;
});

}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Requesting Location Permission'),
),
body:Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: new Text(
"Requesting Location Permission...",
textAlign: TextAlign.center
),
)
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
onPressed: () {
requestLocationPermission(context);
},
child: Text('Get Location Permission'),
color: Colors.green
),
),
Center(
child: Text(position.toString()),
)
]
),
);
}
}

=======
Debug window:

Syncing files to device iPhone 6s...
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_ALREADY_REQUESTING_PERMISSION, A request for permissions is already running, please wait for it to finish before doing another request., null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)

#2 LocationPermissions.requestPermissions (package:location_permissions/src/location_permissions.dart:70:45)

#3 Geolocator._getLocationPermission (package:geolocator/geolocator.dart:195:12)

#4 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:91:47)

#5 _MyHomePageState.requestLocationPermission (package:flutterlocationmap/main.dart:34:51)

#6 _MyHomePageState.build. (package:flutterlocationmap/ma<…>

Conclusion:

It doesn't return the longitude and latitude. Frozen.

@Viktoru
Copy link

Viktoru commented Jul 30, 2019

Sorry, I was missing these: it works

NSLocationWhenInUseUsageDescription
This app needs access to location when open.
NSLocationAlwaysUsageDescription
This app needs access to location when in the background.
NSLocationAlwaysAndWhenInUseUsageDescription
This app needs access to location when open and in the background.

@Theunodb
Copy link

Theunodb commented Jun 9, 2020

Ps.
You need all 4:
NSLocationUsageDescription
NSLocationAlwaysUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription

Only after running the app directly in xcode did the message appear that stated there are missing permissions in the info.plist

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants