ABAddressBookCreate(),ABAddressBookGetGroupCount,... return @"0x00000000 <nil>"?

Oma*_*arj 6 iphone objective-c abaddressbook ios ios5

我正在尝试获取组名,但经过多次调用此方法"由用户重新加载联系人",它会给出nil值和以下错误.

-(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
Run Code Online (Sandbox Code Playgroud)

所以我使用本机通知让我知道什么时候addressbook被修改以减少我访问的时间addressbook,但是如果用户进行许多更新并且每次addrssbook修改必须调用此meathod或任何其他相关的addressbook.

所以还需要你的帮助???

Moh*_*abi 0

ABAddressBookRef为什么您不尝试使用以下方法来尽量减少创建和访问的时间:

void ABAddressBookRegisterExternalChangeCallback (
   ABAddressBookRef addressBook,
   ABExternalChangeCallback callback,
   void *context
);
Run Code Online (Sandbox Code Playgroud)

这允许您的应用程序知道地址簿何时被外部修改。并让您知道您需要重新访问地址簿。

对于您发布的方法来说,同样的事情,每次调用它时都会创建具有对地址簿的新访问权限的新对象