Skip to content

Commit

Permalink
Merge pull request #9 from phinguyen712/SODEV-15050
Browse files Browse the repository at this point in the history
fixed ios address book pop up bug
  • Loading branch information
doctadre authored Jan 25, 2019
2 parents 1b9cbdf + 46e4f67 commit b15c944
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions ios/ContactPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,33 @@ - (instancetype)init {
self.resolve = resolve;
self.reject = reject;
self.pickerController.peoplePickerDelegate = self;

if (ABAddressBookGetAuthorizationStatus() != kABAuthorizationStatusAuthorized) {
ABAddressBookRequestAccessWithCompletion(self.addressBookRef, ^(bool granted, CFErrorRef error) {
if (granted) {
[self.root presentViewController:self.pickerController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[root presentViewController:self.pickerController animated:YES completion:nil];
});
} else {
self.reject(@"access_denied", @"We need access to your contacts to use this feature, please go into your settings and enable it.",(__bridge NSError *)error);
}
});
} else {
[self.root presentViewController:self.pickerController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[root presentViewController:self.pickerController animated:YES completion:nil];
});
}
}
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
didSelectPerson:(ABRecordRef)person {
ABMutableMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty);
NSArray *emails = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);
[self.root dismissViewControllerAnimated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[root dismissViewControllerAnimated:YES completion:nil];
});
self.resolve(emails);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-contact-picker",
"version": "4.0.0",
"version": "6.0.0",
"description": "A contact picker module for React Native",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b15c944

Please sign in to comment.