2013-04-02 61 views
2

我開發了應用程序來從通訊簿數據庫中獲取聯繫人。爲此,實現的代碼對於iOS 6.0版本來說是很好的代碼,但是它在iOS 6.1.3上崩潰了。從iOS版本6.1.3的通訊簿數據庫中獲取聯繫人時發生崩潰?

,我已經實現了獲取從地址簿數據庫中的聯繫人代碼:

ABAddressBookRef addressBook; 

if ([self isABAddressBookCreateWithOptionsAvailable]) { 
    // iOS 6 
    CFErrorRef error = nil; 
    addressBook = ABAddressBookCreateWithOptions(NULL,&error); 
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { }); 
    ABAddressBookRevert(addressBook); 
} else { 
    // iOS 4/5 
    addressBook = ABAddressBookCreate(); 
} 

-(BOOL)isABAddressBookCreateWithOptionsAvailable 
{ 
    return &ABAddressBookCreateWithOptions != NULL; 
} 

請幫助我。

+0

運行如何將有關崩潰的一些細節?例如。一個符號化的崩潰報告,所以我們知道問題是什麼。我想你不希望這是一個謎語,對吧? :) – Kerni

+0

從數據庫獲取數據時,它始終爲ios版本6.1.3返回null。 –

回答

0

我不知道該代碼會崩潰或沒有,但我想這應該在的iOS 6.1.3

-(IBAction)btnShowContactClicked { 
//ABAddressBookRef addressBook = ABAddressBookCreate(); 
CFErrorRef *aberror = NULL; 
addressBook = ABAddressBookCreateWithOptions(NULL, aberror); 
__block BOOL accessGranted = NO; 

if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6 
    dispatch_semaphore_t sema = dispatch_semaphore_create(0); 

    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { 
     accessGranted = granted; 
     dispatch_semaphore_signal(sema); 
    }); 

    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); 
    dispatch_release(sema); 
} 
else { // we're on iOS 5 or older 
    accessGranted = YES; 
} 

if (accessGranted) { 
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; 
    picker.peoplePickerDelegate = self; 
    [self presentViewController:picker animated:YES completion:nil]; 
    // //[self.navigationController presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 
} 
相關問題