Repository: cordova-plugin-contacts Updated Branches: refs/heads/master 039947aab -> 617fb764b
CB-9770 Request user permissions before picking a contact Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/617fb764 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/617fb764 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/617fb764 Branch: refs/heads/master Commit: 617fb764bf1c7047cfe02cf346771dd7fa38ed40 Parents: 039947a Author: Vladimir Kotikov <v-vlk...@microsoft.com> Authored: Tue Nov 24 15:46:25 2015 +0300 Committer: Vladimir Kotikov <v-vlk...@microsoft.com> Committed: Tue Nov 24 16:30:13 2015 +0300 ---------------------------------------------------------------------- src/ios/CDVContacts.m | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/617fb764/src/ios/CDVContacts.m ---------------------------------------------------------------------- diff --git a/src/ios/CDVContacts.m b/src/ios/CDVContacts.m index 53fd67b..d5dd958 100644 --- a/src/ios/CDVContacts.m +++ b/src/ios/CDVContacts.m @@ -192,9 +192,33 @@ callbackId:command.callbackId className:command.className methodName:command.methodName]; - - [self chooseContact:newCommand]; - + + // First check for Address book permissions + ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus(); + if (status == kABAuthorizationStatusAuthorized) { + [self chooseContact:newCommand]; + return; + } + + CDVPluginResult *errorResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsInt:PERMISSION_DENIED_ERROR]; + + // if the access is already restricted/denied the only way is to fail + if (status == kABAuthorizationStatusRestricted || status == kABAuthorizationStatusDenied) { + [self.commandDelegate sendPluginResult: errorResult callbackId:command.callbackId]; + return; + } + + // if no permissions granted try to request them first + if (status == kABAuthorizationStatusNotDetermined) { + ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { + if (granted) { + [self chooseContact:newCommand]; + return; + } + + [self.commandDelegate sendPluginResult: errorResult callbackId:command.callbackId]; + }); + } } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org