crashes when calling requestPermissions() on a denied permission
not crash
press the button
deny
press again
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title});
final String title;
@override
Widget build(BuildContext context) {
return StateWidget();
}
}
class StateWidget extends StatefulWidget {
StateWidget({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return StateWidgetState();
}
}
class StateWidgetState extends State<StateWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: MaterialButton(
child: Text('Press me'),
onPressed: () async {
try {
var permissionStatus =
await PermissionHandler().checkPermissionStatus(
PermissionGroup.contacts,
);
print("{ermission status: $permissionStatus");
if (permissionStatus == PermissionStatus.granted) {
return;
}
final Map<PermissionGroup, PermissionStatus> status =
await PermissionHandler().requestPermissions(
[PermissionGroup.contacts],
);
print("Contacts sync. $status");
} catch (e, st) {
print(" ERROR $e ST $st");
}
},),
),
);
}
}
Flutter doctor output:
$ flutter doctor -v
[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.14.4 18E226, locale en-US)
• Flutter version 1.9.1+hotfix.4 at /Users/jaleel/jalibs/flutter
• Framework revision cc949a8e8b (3 weeks ago), 2019-09-27 15:04:59 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
• Android SDK at /Users/jaleel/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• CocoaPods version 1.7.5
[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 33.3.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[✓] VS Code (version 1.35.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.1.0
[✓] Connected device (1 available)
• iPhone Xs • 025BE904-1E8D-4D34-AAA7-B972A3E363EA • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)
Version: 1.x
Platform:
flutter run --verbose output:
[+2915 ms] [DEVICE LOG] 2019-10-15 15:29:15.465135-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426740, Description: TCCAccessRequest() IPC
[ +2 ms] [DEVICE LOG] 2019-10-15 15:29:15.467608-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426741, Description: TCCAccessRequest() IPC
[ +11 ms] [DEVICE LOG] 2019-10-15 15:29:15.479460-0700 localhost Runner[82201]: (Flutter) flutter: {ermission status: PermissionStatus.unknown
[ ] flutter: {ermission status: PermissionStatus.unknown
[ ] [DEVICE LOG] 2019-10-15 15:29:15.481184-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426742, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.481257-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426743, Description: TCCAccessRequest() IPC
[ +2 ms] [DEVICE LOG] 2019-10-15 15:29:15.483971-0700 localhost Runner[82201]: (Contacts) Created Activity ID: 0x426744, Description: RequestAccessForContacts
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484030-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426745, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484074-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426746, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484096-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426747, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484312-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426748, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484368-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x426749, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484394-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674a, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:15.484468-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674b, Description: TCCAccessRequest() IPC
[+1708 ms] [DEVICE LOG] 2019-10-15 15:29:17.193255-0700 localhost Runner[82201]: (Contacts) [com.apple.contacts:Contacts] Contacts TCC acccess request was denied
[ +1 ms] [DEVICE LOG] 2019-10-15 15:29:17.193351-0700 localhost Runner[82201]: (Contacts) [com.apple.contacts:Contacts] Contacts TCC acccess request was denied
[ ] [DEVICE LOG] 2019-10-15 15:29:17.195005-0700 localhost Runner[82201]: (Contacts) [com.apple.contacts:Contacts] Contacts acccess was NOT granted
[ ] [DEVICE LOG] 2019-10-15 15:29:17.195818-0700 localhost Runner[82201]: (Flutter) flutter: Contacts sync. {PermissionGroup.contacts: PermissionStatus.denied}
[ ] flutter: Contacts sync. {PermissionGroup.contacts: PermissionStatus.denied}
[+8254 ms] [DEVICE LOG] 2019-10-15 15:29:25.450375-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674c, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.450450-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674d, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.450749-0700 localhost Runner[82201]: (Flutter) flutter: {ermission status: PermissionStatus.denied
[ ] [DEVICE LOG] 2019-10-15 15:29:25.451124-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674e, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.451203-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x42674f, Description: TCCAccessRequest() IPC
[ ] flutter: {ermission status: PermissionStatus.denied
[ ] [DEVICE LOG] 2019-10-15 15:29:25.451860-0700 localhost Runner[82201]: (Flutter) flutter: Contacts sync. {PermissionGroup.contacts: PermissionStatus.denied}
[ ] flutter: Contacts sync. {PermissionGroup.contacts: PermissionStatus.denied}
[ +1 ms] [DEVICE LOG] 2019-10-15 15:29:25.452628-0700 localhost Runner[82201]: (Contacts) Created Activity ID: 0x4278c0, Description: RequestAccessForContacts
[ ] [DEVICE LOG] 2019-10-15 15:29:25.452685-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x4278c1, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.452743-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x4278c2, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.452782-0700 localhost Runner[82201]: (Contacts) [com.apple.contacts:Contacts] Contacts acccess was NOT granted
[ ] [DEVICE LOG] 2019-10-15 15:29:25.452907-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] A promise was finished with a nil error.
[ +38 ms] [DEVICE LOG] 2019-10-15 15:29:25.490911-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] Call stack: (
[ ] [DEVICE LOG] 0 ContactsFoundation 0x000000011aa0a12a -[CNFuture finishWithError:] + 52
[ +4 ms] [DEVICE LOG] 1 Contacts 0x0000000105fcea82 __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke_2 + 187
[ ] [DEVICE LOG] 2 Contacts 0x000000010600bc71 +[CNAuthorization requestAccessForEntityType:completionHandler:] + 77
[ ] [DEVICE LOG] 3 Contacts 0x0000000105f7ec44 -[CNXPCDataMapper requestAccessForEntityType:completionHandler:] + 123
[ ] [DEVICE LOG] 4 Contacts 0x0000000105fce99a __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke + 174
[ ] [DEVICE LOG] 5 libsystem_trace.dylib 0x000000010a5d6f00 os_activity_apply_f + 66
[ ] [DEVICE LOG] 6 Contacts 0x0000000106022d52 -[_CNContactsLogger requestingAccessForContacts:] + 225
[ ] [DEVICE LOG] 7 Contacts 0x0000000105fce8a4 -[CNDataMapperContactStore requestAccessForEntityType:] + 177
[ ] [DEVICE LOG] 8 Contacts 0x0000000105fa
[ ] 0 ContactsFoundation 0x000000011aa0a12a -[CNFuture finishWithError:] + 52
[ ] 1 Contacts 0x0000000105fcea82 __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke_2 + 187
[ ] 2 Contacts 0x000000010600bc71 +[CNAuthorization requestAccessForEntityType:completionHandler:] + 77
[ ] 3 Contacts 0x0000000105f7ec44 -[CNXPCDataMapper requestAccessForEntityType:completionHandler:] + 123
[ +13 ms] 4 Contacts 0x0000000105fce99a __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke + 174
[ ] 5 libsystem_trace.dylib 0x000000010a5d6f00 os_activity_apply_f + 66
[ ] 6 Contacts 0x0000000106022d52 -[_CNContactsLogger requestingAccessForContacts:] + 225
[ ] 7 Contacts 0x0000000105fce8a4 -[CNDataMapperContactStore requestAccessForEntityType:] + 177
[ ] 8 Contacts 0x0000000105fa
[ ] [DEVICE LOG] 2019-10-15 15:29:25.491183-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] A promise was finished incorrectly.
[ ] [DEVICE LOG] 2019-10-15 15:29:25.491318-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] Result: (null)
[ ] [DEVICE LOG] 2019-10-15 15:29:25.491430-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] Error : (null)
[ ] [DEVICE LOG] 2019-10-15 15:29:25.497189-0700 localhost Runner[82201]: (ContactsFoundation) [Rx] Call stack: (
[ ] [DEVICE LOG] 0 ContactsFoundation 0x000000011aa09ed8 -[CNFuture finishWithResult:error:] + 290
[ ] [DEVICE LOG] 1 Contacts 0x0000000105fcea82 __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke_2 + 187
[ +3 ms] [DEVICE LOG] 2 Contacts 0x000000010600bc71 +[CNAuthorization requestAccessForEntityType:completionHandler:] + 77
[ ] [DEVICE LOG] 3 Contacts 0x0000000105f7ec44 -[CNXPCDataMapper requestAccessForEntityType:completionHandler:] + 123
[ ] [DEVICE LOG] 4 Contacts 0x0000000105fce99a __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke + 174
[ ] [DEVICE LOG] 5 libsystem_trace.dylib 0x000000010a5d6f00 os_activity_apply_f + 66
[ ] [DEVICE LOG] 6 Contacts 0x0000000106022d52 -[_CNContactsLogger requestingAccessForContacts:] + 225
[ ] [DEVICE LOG] 7 Contacts 0x0000000105fce8a4 -[CNDataMapperContactStore requestAccessForEntityType:] + 177
[ ] [DEVICE LOG] 8 Contacts 0x0000
[ ] [DEVICE LOG] 2019-10-15 15:29:25.497515-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x4278c3, Description: TCCAccessRequest() IPC
[ ] [DEVICE LOG] 2019-10-15 15:29:25.497595-0700 localhost Runner[82201]: (TCC) Created Activity ID: 0x4278c4, Description: TCCAccessRequest() IPC
[ +1 ms] [DEVICE LOG] 2019-10-15 15:29:25.497742-0700 localhost Runner[82201]: (Contacts) [com.apple.contacts:Contacts] Contacts TCC acccess request was denied
[ ] 0 ContactsFoundation 0x000000011aa09ed8 -[CNFuture finishWithResult:error:] + 290
[ ] 1 Contacts 0x0000000105fcea82 __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke_2 + 187
[ ] 2 Contacts 0x000000010600bc71 +[CNAuthorization requestAccessForEntityType:completionHandler:] + 77
[ ] 3 Contacts 0x0000000105f7ec44 -[CNXPCDataMapper requestAccessForEntityType:completionHandler:] + 123
[ ] 4 Contacts 0x0000000105fce99a __55-[CNDataMapperContactStore requestAccessForEntityType:]_block_invoke + 174
[ ] 5 libsystem_trace.dylib 0x000000010a5d6f00 os_activity_apply_f + 66
[ ] 6 Contacts 0x0000000106022d52 -[_CNContactsLogger requestingAccessForContacts:] + 225
[ ] 7 Contacts 0x0000000105fce8a4 -[CNDataMapperContactStore requestAccessForEntityType:] + 177
[ ] 8 Contacts 0x0000
follow up - is there a way to bring up the request permissions popup again after denying the request? why does denying it once permanently deny?
I 'm countering the same issue, when i denie permission my app crash
You should add some logic to manage this in iOS to prevent the crash.
PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.contacts);
if (permission == PermissionStatus.denied && Platform.isIOS) {
// do not request permissions again.
}
any news on that?
Running this with the latest Flutter and permission_handler version does not result in an error.
Please resubmit a new issue when a problem occurs.
Most helpful comment
follow up - is there a way to bring up the request permissions popup again after denying the request? why does denying it once permanently deny?