flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

Permission.locationAlways causes iOS 13.5 crash

Open jjonte opened this issue 4 years ago • 2 comments

🐛 Bug Report

When running the sample application, if you press the locationAlways permission, it crashes the application.

Stacktrace:

*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23e3cf0e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff50ba89b2 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23e3cad9 -[NSException raise] + 9
	3   Runner                              0x00000001051783f0 -[LocationPermissionStrategy requestPermission:completionHandler:] + 832
	4   Runner                              0x000000010517a370 -[PermissionManager requestPermissions:completion:] + 656
	5   Runner                              0x0000000105179b6e -[PermissionHandlerPlugin handleMethodCall:result:] + 1118
	6   Flutter                             0x00000001074969df __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
	7   Flutter           <…>
Lost connection to device.

Expected behavior

It prompts the user for the appropriate permissions.

Reproduction steps

Run:

import 'dart:io';

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

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

/// Example Flutter Application demonstrating the functionality of the
/// Permission Handler plugin.
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              icon: const Icon(Icons.settings),
              onPressed: () async {
                var hasOpened = openAppSettings();
                debugPrint('App Settings opened: ' + hasOpened.toString());
              },
            )
          ],
        ),
        body: Center(
          child: ListView(
              children: Permission.values
                  .where((Permission permission) {
                    if (Platform.isIOS) {
                      return permission != Permission.unknown &&
                          permission != Permission.sms &&
                          permission != Permission.storage &&
                          permission != Permission.ignoreBatteryOptimizations &&
                          permission != Permission.accessMediaLocation;
                    } else {
                      return permission != Permission.unknown &&
                          permission != Permission.mediaLibrary &&
                          permission != Permission.photos &&
                          permission != Permission.reminders;
                    }
                  })
                  .map((permission) => PermissionWidget(permission))
                  .toList()),
        ),
      ),
    );
  }
}

/// Permission widget which displays a permission and allows users to request
/// the permissions.
class PermissionWidget extends StatefulWidget {
  /// Constructs a [PermissionWidget] for the supplied [Permission].
  const PermissionWidget(this._permission);

  final Permission _permission;

  @override
  _PermissionState createState() => _PermissionState(_permission);
}

class _PermissionState extends State<PermissionWidget> {
  _PermissionState(this._permission);

  final Permission _permission;
  PermissionStatus _permissionStatus = PermissionStatus.undetermined;

  @override
  void initState() {
    super.initState();

    //_listenForPermissionStatus();
  }

  void _listenForPermissionStatus() async {
    final status = await _permission.status;
    setState(() => _permissionStatus = status);
  }

  Color getPermissionColor() {
    switch (_permissionStatus) {
      case PermissionStatus.denied:
        return Colors.red;
      case PermissionStatus.granted:
        return Colors.green;
      default:
        return Colors.grey;
    }
  }

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(_permission.toString()),
      subtitle: Text(
        _permissionStatus.toString(),
        style: TextStyle(color: getPermissionColor()),
      ),
      trailing: IconButton(
          icon: const Icon(Icons.info),
          onPressed: () {
            checkServiceStatus(context, _permission);
          }),
      onTap: () {
        requestPermission(_permission);
      },
    );
  }

  void checkServiceStatus(BuildContext context, Permission permission) async {
    Scaffold.of(context).showSnackBar(SnackBar(
      content: Text((await permission.status).toString()),
    ));
  }

  Future<void> requestPermission(Permission permission) async {
    final status = await permission.request();

    setState(() {
      print(status);
      _permissionStatus = status;
      print(_permissionStatus);
    });
  }
}

Then press LocationAlways.

Configuration

Version: 5.0.0+hotfix.8

Platform:

  • [ x] :iphone: iOS
  • [ ] :robot: Android

jjonte avatar Jun 04 '20 16:06 jjonte

I am having a similar problem. await Permission.notification.request(); works but camera, microphone, location all failed. I am using --flavors so I have configured the permissions inside info-debug.plist. We only have info-debug.plist and info-release.plist. ⁣ ⁣Android works perfectly. iOS crashes with device lost connection.

NuteIla avatar Feb 11 '21 03:02 NuteIla

Hi @jjonte, do you still have this issue if you use the newest version of the permission handler (version ^8.1.4+1)? Please keep in mind to read the setup section of the documentation and update the podfile according to the documentation if needed. Also keep in mind to add the lines as mentioned in the documentation in the info.plist.

Please let me know if this helped you out so I can close this issue!

JDDV avatar Jul 23 '21 13:07 JDDV

I consider this issue to be revolved or outdated. I therefore close this issue. Feel free to reopen when needed.

TimHoogstrate avatar Jun 29 '23 14:06 TimHoogstrate