6

グループ名を取得しようとしていますが、「ユーザーが連絡先をリロードするために」このメソッドを何度も呼び出した後、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

そのため、ネイティブ通知を使用して、addressbookにアクセスする回数を減らすために変更されたときに通知しますがaddressbook、ユーザーが多くの更新を行い、変更されるたびにaddrssbookこのメソッドまたは関連する他のものを呼び出さなければならない場合は、まだ良くありませんaddressbook.

まだあなたの助けが必要です???

4

3 に答える 3

1

ABAddressBookCreateiOS6 で廃止されました。を使用すると、アドレス帳にアクセスできない場合はオブジェクトABAddressBookCreateWithOptionsが返されます。CFErrorRef

于 2012-12-23T14:20:32.553 に答える
0

ABAddressBookRef以下を使用して、作成してアクセスする時間を最小限に抑えようとしないのはなぜですか。

void ABAddressBookRegisterExternalChangeCallback (
   ABAddressBookRef addressBook,
   ABExternalChangeCallback callback,
   void *context
);

これにより、addressBook が外部によっていつ変更されるかをアプリが知ることができます。アドレス帳に再度アクセスする必要があることを知らせます。

メソッドを投稿するのと同じこと、呼び出すたびに、アドレス帳への新しいアクセス権を持つ新しいオブジェクトが作成されます

于 2012-12-30T12:25:22.120 に答える
-1

@thelaws で指摘されているように、IOS6 では ABAddressBookCreateWithOptions を使用する必要があります。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
}

もう 1 つのことは、どこかで groupsName を初期化したことです。..

それとは別に、addressBook変更の通知を取得するためにABExternalChangeCallBackを使用していますか?

連絡先にアクセスしている同じモジュール内にグループコードを配置する必要があると思います。(これが役に立たない場合は、明確にしてください!)

于 2012-12-25T13:58:49.120 に答える