Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

防止获取通讯录失败后,仍然执行获取成功后的回调 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions PPGetAddressBook/PPGetAddressBook/PPGetAddressBook.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ + (void)getOriginalAddressBook:(AddressBookArrayBlock)addressBookArray authoriza

dispatch_async(queue, ^{

NSMutableArray *array = [NSMutableArray array];
__block NSMutableArray *array = [NSMutableArray array];
[kPPAddressBookHandle getAddressBookDataSource:^(PPPersonModel *model) {

[array addObject:model];
Expand All @@ -47,10 +47,13 @@ + (void)getOriginalAddressBook:(AddressBookArrayBlock)addressBookArray authoriza
});
}];

// 将联系人数组回调到主线程
dispatch_async(dispatch_get_main_queue(), ^{
addressBookArray ? addressBookArray(array) : nil ;
});
// 防止Failure后,仍然执行addressBookArray回调
if (array) {// 说明可以打开通讯录获取通讯录信息(也可能通讯录为空)
// 将联系人数组回调到主线程
dispatch_async(dispatch_get_main_queue(), ^{
addressBookArray ? addressBookArray(array) : nil ;
});
}
});

}
Expand Down