ABAddressBookCreate (), ABAddressBookGetGroupCount, ... return @ "0x00000000 <nil>"?
I try to get the group name, but after calling this method multiple times by the "user to reload contacts" it gives nil and the following error.
-(void) getGroupsName { [groupsName removeAllObjects]; //address book object to interact with iPhone contacts. ABAddressBookRef addressbook = ABAddressBookCreate(); //get groups count CFIndex groupsCount = ABAddressBookGetGroupCount(addressbook); //get all available groups as array CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(addressbook); for (int i = 0; i<groupsCount; i++) { //get group of index=i from groups array ABRecordRef group = CFArrayGetValueAtIndex(allGroups, i); //get group name, I use __bridge_transfer to transfer from C to objective-c. [groupsName addObject:(__bridge_transfer NSString*)ABRecordCopyCompositeName(group)]; } CFRelease(allGroups); CFRelease(addressbook); } ////////////////////////////////////////////////////////////// warning: Could not compile statement PRAGMA journal_mode = wal;: unable to open database file error 14 creating properties table: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file warning: Could not compile statement SELECT ROWID FROM ABGroup;: unable to open database file warning: Could not compile statement SELECT ROWID, Name, ExternalIdentifier, StoreID, NULL, NULL, NULL FROM ABGroup;: unable to open database file Therefore, I use my own notification to tell me when the addressbook to receive the change, to reduce the amount of time when I access the addressbook , but itβs still not very good if the user does a lot of updates and every time addrssbook to get modified should call this meathod or Any other related to the addressbook .
so do you need your help ???
Why aren't you trying to minimize the amount of time you created and access ABAddressBookRef using the following:
void ABAddressBookRegisterExternalChangeCallback ( ABAddressBookRef addressBook, ABExternalChangeCallback callback, void *context ); this allows your application to know when the address book will change externally. and tell you that you need to re-access the address book.
The same for your method, which you publish every time you call it, it will create a new object with new access to the address book
As pointed out by @thelaws you need to use ABAddressBookCreateWithOptions in iOS6. if ([[[[UIDevice currentDevice] systemVersion] floatValue]> 5.1) {
ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, NULL); __block BOOL accessGranted = NO; if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { ABAddressBookRequestAccessWithCompletion(ab, ^(bool granted, CFErrorRef error) { // First time access has been granted, add the contact accessGranted = granted; }); } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { // The user has previously given access, add the contact accessGranted = YES; } else { // The user has previously denied access // Send an alert telling user to change privacy setting in settings app } if (accessGranted) { // your code goes here } } else { // your code goes here } Another thing is that you initialized groupsName somewhere? ..
Also, are you using ABExternalChangeCallBack to receive notification of an address book change?
I think you should put the group code in the same module where you access the contacts. (If this does not help you, make it clear!)