Contacts Permission request crashes in production build.
🐛 Bug Report
Contacts permission request crashes for most of the users very first time in production build.
Expected behaviour
Permission should work similar to other permission options for contact permission as well.
Reproduction steps
To reproduce the issue in debug mode we are facing problem. But, In production It is crashing very frequently for the first time when user tries to access contacts.
Configuration
Below is my code to access contacts
@JsonSerializable()
class SyncContacts extends ClientAction {
SyncContacts(String action_name) : super(action_name);
Future<bool> hasPermission(BuildContext context) async {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.contacts);
if (permission == PermissionStatus.granted) {
return true;
} else if (permission == PermissionStatus.denied) {
var openSettings = await ActionsUtility.showPermissionNeededDialog(
context,
"Contacts Permission Required",
"Please enable contacts permission from settings");
if (openSettings) {
await PermissionHandler().openAppSettings();
}
} else if (permission != PermissionStatus.disabled) {
Map<PermissionGroup, PermissionStatus> permissionStatus =
await PermissionHandler()
.requestPermissions([PermissionGroup.contacts]);
return permissionStatus[PermissionGroup.contacts] ==
PermissionStatus.granted;
}
return false;
}
@override
FutureOr<bool> execute(BuildContext context, AppStore store,
Map<String, dynamic> methodVariables) async {
if (await hasPermission(context)) {
var contactsInstance = Contacts.init();
await contactsInstance.getContacts(store, context);
} else {
debugPrint(
"PERMISSION_NOT_GRANTED: Access to contacts data not given/denied");
}
return true;
}
factory SyncContacts.fromJson(Map<String, dynamic> json) =>
_$SyncContactsFromJson(json);
@override
Map<String, dynamic> toJson() => _$SyncContactsToJson(this);
@override
ClientAction clone() => SyncContacts.fromJson(Map.from(toJson()));
}
Below is the Stack trace from firebase
Fatal Exception: NSRangeException
*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
__51-[PermissionManager requestPermissions:completion:]_block_invoke
Fatal Exception: NSRangeException
0 CoreFoundation 0x2241e7ea0 __exceptionPreprocess
1 libobjc.A.dylib 0x2233b9a40 objc_exception_throw
2 CoreFoundation 0x22415f470 _CFArgv
3 CoreFoundation 0x2240cf758 -[__NSArrayM objectAtIndex:]
4 CoreFoundation 0x2240d31b0 -[NSMutableArray removeObject:]
5 Runner 0x100b47ae4 __51-[PermissionManager requestPermissions:completion:]_block_invoke + 53 (PermissionManager.m:53)
6 AddressBook 0x22fdda6a0 __46+[ABSAddressBook requestAccessWithCompletion:]_block_invoke
7 TCC 0x22703e8dc __TCCAccessRequest_block_invoke.77
8 TCC 0x227042a90 __tccd_send_message_block_invoke
9 libxpc.dylib 0x223e48514 _xpc_connection_reply_callout
10 libxpc.dylib 0x223e3bb3c _xpc_connection_call_reply_async
11 libdispatch.dylib 0x223c22504 _dispatch_client_callout3
12 libdispatch.dylib 0x223bda8a8 _dispatch_mach_msg_async_reply_invoke$VARIANT$mp
13 libdispatch.dylib 0x223bd283c _dispatch_kevent_worker_thread
14 libsystem_pthread.dylib 0x223e040ec _pthread_wqthread
15 libsystem_pthread.dylib 0x223e06cec start_wqthread
As I checked the code base in plugin inside PermissionManager.m file
It is crashing while removing the permissionStrategy at line#51
[self->_strategyInstances removeObject:permissionStrategy];
Version: permission_handler: ^4.0.0
Platform:
- [ ] :iphone: iOS
Same problem here it crashes on Simulator when tries to check the permissions for status
is there already an answer to this problem?
No. It must be handled in native code. It could be because of iterating and modifying the same array element. Validation of objects are safe to handle and w.r.t permission, needs to check if any missing key in info.plist or handling permission.
Any update?
Issue should be solved by PR #444