Skip to content

Commit

Permalink
made sure to copy blocks on heap
Browse files Browse the repository at this point in the history
  • Loading branch information
ettore committed Dec 20, 2012
1 parent 08ed4d5 commit 3e91bd2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions clcg_addressbook_utils.m
Expand Up @@ -49,6 +49,9 @@ void clcg_addressbook_load_contacts(CLCGABCallback callback)
{
ABAddressBookRef ab;

// make sure to keep a valid object on the heap
callback = [[callback copy] autorelease];

// check existence of function, only defined in iOS 6
if (&ABAddressBookCreateWithOptions != NULL) {
// iOS 6+
Expand All @@ -57,19 +60,19 @@ void clcg_addressbook_load_contacts(CLCGABCallback callback)
if (error) {
callback(nil, NO, (NSError*)error);
} else {
ABAddressBookRequestAccessWithCompletion(ab, ^(bool granted, CFErrorRef err) {
ABAddressBookRequestAccessWithCompletion(ab, [[^(bool granted, CFErrorRef err) {
// the callback can occur in the background, but the address book must
// be accessed on the thread it was created on
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), [[^{
if (err || !granted) {
callback(nil, granted, (NSError*)err);
} else {
NSMutableArray *people = clcg__process_ab(ab);
callback(people, YES, nil);
CFRelease(ab);
}
});
});
} copy] autorelease]);
} copy] autorelease]);
}
} else {
// iOS 4/5
Expand Down

0 comments on commit 3e91bd2

Please sign in to comment.