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

if permission.isDenied openAppSettings() crash the app

Open 1rach opened this issue 4 years ago • 13 comments

🐛 Bug Report

First, thanks for this very useful plugin !

Expected behavior

I would like to open settings if permission.isDenied... but it doesn't work (tested with permission == Permission.photos or permission == Permission.camera, but other permissions are in the same case), the error :

 thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGKILL
    frame #0: 0x0000000189737198 libsystem_kernel.dylib`mach_msg_trap + 8
libsystem_kernel.dylib`mach_msg_trap:
->  0x189737198 <+8>: ret    

libsystem_kernel.dylib`mach_msg_overwrite_trap:
    0x18973719c <+0>: mov    x16, #-0x20
    0x1897371a0 <+4>: svc    #0x80
    0x1897371a4 <+8>: ret    
Target 0: (Runner) stopped.

Reproduction steps

You can test it with the default example App : 1/ Launch the app, click on a permission then refuse. 2/ Open the settings via the button on AppBar 3/ Set the permission you have refused to True

The app crashs.

Example of basic code :

FlatButton(
                child: Text("Ok"),
                onPressed: () async {
                  bool isDenied = await permission.isDenied;

                  if (isDenied)
                    openAppSettings();
                  else
                    requestPermission(permission);

                  //  Navigator.of(context).pop();
                },
              ),

Configuration

Ipad (IOS : 13.4.1) Version of plugin : ^5.0.0+hotfix.6

Platform:

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

Could you confirm ?

thanks,

1rach avatar May 18 '20 12:05 1rach

I am also getting the same issue on android platform.

TheAlphamerc avatar May 26 '20 12:05 TheAlphamerc

Just want to add that when using "openAppSettings" in iOS the OS will kill the app sending "Message from debugger: Terminated due to signal 9", this is iOS way of reseting the app so the new changes take place. In my tests this used to work a bit differently in iOS <= 13. Anyway, now expect you app to be terminated when calling this method. In Android it is working fine.

jeanadam avatar Nov 13 '20 18:11 jeanadam

I also have the same problem. Do you have any updates on this topic?

wiktoriasobczyk avatar Jan 11 '21 07:01 wiktoriasobczyk

For permission_handler: ^5.0.1+1 openAppSettings() is totally broken on both iOS and Android. It does not matter what the status of any permission is, from what I can tell.

On Android 10 (Galaxy A10e) I get an error when I try to call openAppSettings().

D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 0
D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 1
D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 0
D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 1
D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 0
D/ViewRootImpl@89cbb89[MainActivity](32733): ViewPostIme pointer 1
E/flutter (32733): [ERROR:flutter/lib/ui/ui_dart_state.cc(184)] Unhandled Exception: Stack Overflow
E/flutter (32733): #0      _ZoneDelegate.handleUncaughtError (dart:async/zone.dart:745:3)
E/flutter (32733): #1      runZonedGuarded.<anonymous closure> (dart:async/zone.dart:1600:16)
E/flutter (32733): #2      _CustomZone.handleUncaughtError (dart:async/zone.dart:1073:19)
E/flutter (32733): #3      Future._propagateToListeners (dart:async/future_impl.dart:622:16)
E/flutter (32733): #4      Future._completeError (dart:async/future_impl.dart:549:5)
E/flutter (32733): #5      _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13)

On iOS 14.3 (iPhone 8 Plus) I get an error when I try to call openAppSettings().

[VERBOSE-2:ui_dart_state.cc(184)] Unhandled Exception: Stack Overflow
#0      PermissionsStore.openAppSettings
package:mh/…/permissions/permissions_store.dart:41
#1      _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:48:64)
#2      _rootRunBinary (dart:async/zone.dart:1210:47)
#3      _CustomZone.runBinary (dart:async/zone.dart:1104:19)
#4      _FutureListener.handleError (dart:async/future_impl.dart:164:20)
#5      Future._propagateToListeners.handleError (dart:async/future_impl.dart:720:47)
#6      Future._propagateToListeners (dart:async/future_impl.dart:741:24)
#7      Future._completeError (dart:async/future_impl.dart:549:5)
#8      _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13)

lukepighetti avatar Jan 20 '21 18:01 lukepighetti

I had a shadowing issue that caused the problem above. My issue is resolved. Please see: https://github.com/Baseflow/flutter-permission-handler/issues/368#issuecomment-763854735

lukepighetti avatar Jan 20 '21 18:01 lukepighetti

I have a similar problem but my application does not crash but freezes. I have checked that app gets restarted when some specific settings (not all) are changed at OS settings level, so that restart signal is getting problematic I don't know why. The fact is that if app is already open, the app freezes due to some problem with SIGKILL.

I solved this problem with a simple workaround. I kill the app some milliseconds after I call the openAppSettings...

openAppSettings();
Future.delayed(Duration(milliseconds: 500), () => exit(0));

After the user changes the setting at OS settings level and return to the app, the app restarts automatically with no freeze.

luis901101 avatar Aug 05 '21 19:08 luis901101

Hello! Was anybody able to resolve this problem? the iOS app is crashing when opening the app settings after any permission is declined.

nazdream avatar Sep 08 '21 14:09 nazdream

@nazdream have you tried the solution above your comment? It worked for me.

luis901101 avatar Sep 08 '21 15:09 luis901101

Same issue for me with iOS

openAppSettings and then returning to app seems to crash/restart the app.

carman247 avatar Dec 13 '21 12:12 carman247

I have a similar problem but my application does not crash but freezes. I have checked that app gets restarted when some specific settings (not all) are changed at OS settings level, so that restart signal is getting problematic I don't know why. The fact is that if app is already open, the app freezes due to some problem with SIGKILL.

I solved this problem with a simple workaround. I kill the app some milliseconds after I call the openAppSettings...

openAppSettings();
Future.delayed(Duration(milliseconds: 500), () => exit(0));

After the user changes the setting at OS settings level and return to the app, the app restarts automatically with no freeze.

  1. This code does not work for me on iOS 15
  2. From what I'm reading on StackOverflow (https://stackoverflow.com/questions/45109557/flutter-how-to-programmatically-exit-the-app), Apple may reject your app for programmatically exiting. However, the best guidance that I can find from Apple is an archived answer that discourages the use of exit (https://developer.apple.com/library/archive/qa/qa1561/_index.html). So with certainty, Apple discouraged the use of exit in the past.
  3. Flutter recommends the use of SystemNavigator.pop() (https://api.flutter.dev/flutter/services/SystemNavigator/pop.html) over exit, but that apparently does not work on iOS.

I'm also reading that iOS by design closes the app when setting changes are made (https://github.com/ky1vstar). But I'm not sure that's true. If iOS closes an app there should be an alert to the user, as that is what was recommended for developer apps (https://developer.apple.com/library/archive/qa/qa1561/_index.html). So either closing the app is a bug, or an oversight. Regardless, anytime an app closes by iOS, exit, or SystemNavigator.pop() - the user should be informed that the app will be closed, and why.

ex-tag avatar Dec 28 '21 10:12 ex-tag

Any update regarding this bug? Still facing same issue

danielpartogi avatar Jan 27 '22 01:01 danielpartogi

I'm facing this same issue... My app crashes after manually enable Camera permission on iOS...

emersonsiega avatar Feb 14 '22 15:02 emersonsiega

This is not a problem of this lib. If you try to run you app without doing anything and open iOS settings and try to change app permission the app exit automatically. This is my log in profile mode:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGKILL
    frame #0: 0x0000000217a534e0 libsystem_kernel.dylib`mach_msg_trap + 8
libsystem_kernel.dylib`mach_msg_trap:
->  0x217a534e0 <+8>: ret    
libsystem_kernel.dylib`mach_msg_overwrite_trap:
    0x217a534e4 <+0>: mov    x16, #-0x20
    0x217a534e8 <+4>: svc    #0x80
    0x217a534ec <+8>: ret    
Target 0: (Runner) stopped.
Lost connection to device.

I think that the problem in not directly connected to this lib.

If you want to test create a simple empty app and try move in background the app and change for example photo access permission, when you do that the app is restarted automatically.

carmas123 avatar Mar 27 '22 12:03 carmas123

Hi @1rach, thank you for opening this issue and providing the necessary information!

As pointed out in the thread, this is intended iOS behavior. I am therefore going to close this issue. See also #509.

JeroenWeener avatar Jul 03 '23 14:07 JeroenWeener

Just want to add that when using "openAppSettings" in iOS the OS will kill the app sending "Message from debugger: Terminated due to signal 9", this is iOS way of reseting the app so the new changes take place. In my tests this used to work a bit differently in iOS <= 13. Anyway, now expect you app to be terminated when calling this method. In Android it is working fine.

Is there a way to fix this issue for ios?

lydia-debug avatar Sep 05 '23 20:09 lydia-debug