2012-12-23 12 views
6

Ich versuche, Gruppen Name zu bekommen, aber nach langer Zeit diese Methode "vom Benutzer zu laden Kontakte laden" geben Sie die nil Wert und den folgenden Fehler.ABAddressBookCreate(), ABAddressBookGetGroupCount, ... zurück @ "0x00000000 <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 

So verwende ich die ursprüngliche Benachrichtigung, mich zu informieren, wenn addressbook geändert bekommt Anzahl von Zeit zu verringern ich die addressbook zugreifen, aber immer noch nicht gut durch die Zeit, wenn der Benutzer viele Update machen und jede Zeit addrssbook get modifiziert muss dieses meathod oder irgendein anderes bezogen auf addressbook nennen.

so brauchen Sie noch Ihre Hilfe ???

+0

Bitte sehen Adresse http://stackoverflow.com/questions/13053976/catch-22 -nach der Dokumentation-für-Adressbuch-Verwendung-mit-ios-6 – rmaddy

+0

@rmaddy es ist nicht der gleiche Fall, mein Code erhalten alle Kontakte beim ersten Mal und jedes Mal, aber ich habe Reload-Taste Wenn der Benutzer mehr als 20 Mal darauf klickt, wird der Fehler über – Omarj

+0

zurückgegeben. Leider habe ich nicht bemerkt, dass Sie das Problem erst nach vielen Iterationen hatten. – rmaddy

Antwort

0

Warum Tring Sie nicht Anzahl der Zeit zu minimieren, die Sie erstellen und die ABAddressBookRef zugreifen, indem Sie die folgenden Schritte aus:

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

dies erlauben, Ihre App wissen, wenn das Adressbuch von extern ändern. und Sie wissen zu lassen, dass Sie erneut auf das Adressbuch zugreifen müssen.

Das gleiche für Ihre Methode, die Sie es schreiben, jedes Mal wenn Sie es nennen neues Objekt mit neuen Zugang erstellen Buch

+1

thx es ist Arbeit für mich, für jetzt kein Absturz und keine SQL-Kriegserklärung :) – Omarj

1

ABAddressBookCreate wurde in iOS6 veraltet. Verwenden Sie ABAddressBookCreateWithOptions, es wird ein CFErrorRef Objekt zurückgegeben, wenn Sie keinen Zugriff auf das Adressbuch haben.

+0

geben Sie mir immer noch das gleiche Problem nach dem Aufruf der Methode viele Male wird es null zurückgeben, so dass ich denke, dass von der SDK es selbst? – Omarj

+0

Haben Sie versucht, den CFErrorRef anzuschauen? –

+0

wie Sie sehen, es ist keine Warnung ein Fehler, so kann es nicht protokollieren oder tun dünn für & Fehler – Omarj

-1

Wie in @thelaws angegeben, müssen Sie ABAddressBookCreateWithOptions in IOS6 verwenden. 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 
} 

Eine andere Sache ist, Sie initialisiert haben, GROUPS irgendwo? ..

davon abgesehen, sind für Sie ABExternalChangeCallBack mit immer Benachrichtigung der AdresseBuchänderung?

Ich denke, Sie sollten Gruppencode innerhalb des gleichen Moduls setzen, wo Sie auf Kontakte zugreifen. (Wenn dies nicht hilft, kann klären)

+0

erste Sache yeas ich ABEXternalChangeCallBack verwenden und das gibt mir mehr 10 Mal um einen Absturz zu vermeiden "wenn Benutzer aktualisieren dann die App benachrichtigt Zugriff auf das Adressbuch, wenn dies mehrfach passiert ist ". Zweitens: es ist das gleiche für Kontakte, wenn ich es mehrmals benötige, es wird abstürzen oder zu mir zurückkehren Nullwert. also das hilft nicht :( – Omarj

+1

Korrigieren Sie im Prinzip, aber -1 für den floatValue der Systemversion. Das ist NICHT die empfohlene Möglichkeit, um API Verfügbarkeit zu überprüfen. –