Skip to content

Commit

Permalink
Merge pull request #7 from OutSystems/fix/RMET-306/crash-deleting-con…
Browse files Browse the repository at this point in the history
…tact

RMET-306 - Crash on deleting contact
  • Loading branch information
CarlsCorrea authored Oct 23, 2020
2 parents f03783d + c90dcc5 commit da2bd7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-contacts",
"version": "3.0.1-OS2",
"version": "3.0.1-OS3",
"description": "Cordova Contacts Plugin",
"types": "./types/index.d.ts",
"cordova": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
id="cordova-plugin-contacts"
version="3.0.1-OS2">
version="3.0.1-OS3">

<name>Contacts</name>
<description>Cordova Contacts Plugin</description>
Expand Down
18 changes: 10 additions & 8 deletions src/ios/CDVContacts.m
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,15 @@ - (void)createAddressBook:(CDVAddressBookWorkerBlock)workerBlock
// TODO: this probably should be reworked - seems like the workerBlock can just create and release its own AddressBook,
// and also this important warning from (http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/BasicObjects.html):
// "Important: Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance."
ABAddressBookRef addressBook;

CFErrorRef error = nil;
// CFIndex status = ABAddressBookGetAuthorizationStatus();
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
// NSLog(@"addressBook access: %lu", status);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_async(dispatch_get_main_queue(), ^{
ABAddressBookRef addressBook;
CFErrorRef error = nil;
// CFIndex status = ABAddressBookGetAuthorizationStatus();
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
// NSLog(@"addressBook access: %lu", status);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
// callback can occur in background, address book must be accessed on thread it was created on
dispatch_sync(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
workerBlock(NULL, [[CDVAddressBookAccessError alloc] initWithCode:UNKNOWN_ERROR]);
} else if (!granted) {
Expand All @@ -608,6 +608,8 @@ - (void)createAddressBook:(CDVAddressBookWorkerBlock)workerBlock
}
});
});
});

}

@end

0 comments on commit da2bd7b

Please sign in to comment.