2012-12-23 2 views
6

그룹 이름을 가져 오려고하는데이 메서드를 "연락처를 다시로드하기 위해 사용자가"호출하면 nil 값과 다음 오류가 발생합니다. 사용자가 여러 업데이트를 모든 시간을 할 경우ABAddressBookCreate(), ABAddressBookGetGroupCount, ... @ "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 

그래서 난 아직도 그 때까지는 좋지 나는 addressbook 액세스 시간의 수를 감소하도록 수정 얻을 때 addressbook 알려 주시기 위해 기본 알림을 사용하지만, addrssbook GET 수정 된 것은이 가벼운 천막 또는 addressbook과 관련된 다른 하나를 호출해야합니다.

그래도 도움이 필요합니까 ??? ???

+0

참조하십시오 http://stackoverflow.com/questions/13053976/catch-22 -에 대한 문서에 대한 설명 - 주소록 사용 - ios-6 – rmaddy

+0

@rmaddy 같은 경우는 아니지만, 처음부터 모든 코드를 얻을 수 있지만 매번 재로드 버튼이 있습니다. 사용자가 20 번 이상 클릭하면 위의 오류가 반환됩니다. – Omarj

+0

죄송합니다. 많은 반복 작업 후에 만 ​​문제가 발생했다는 것을 깨닫지 못했습니다. – rmaddy

답변

0

을 당신이 만들 시간 수를 최소화하고 사용하여 ABAddressBookRef에 액세스 할 수 트링되지 않는 이유는 다음

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

이에 허용하여 app은 addressBook이 외부에서 수정 될 때 알 수 있습니다. 주소록에 다시 액세스해야한다는 사실을 알려줍니다.

당신이 그것을 게시하는 방법에 따라 같은 일, 당신이 책을 해결하기 위해 새로운 접근과 새로운 객체를 생성합니다 호출 할 때마다

+1

thx 그것은 나를 위해 일합니다. 이제는 크래시가 없습니다. SQL 전쟁 없음 :) – Omarj

1

ABAddressBookCreate은 iOS6에서 권장되지 않습니다. ABAddressBookCreateWithOptions을 사용하면 주소록에 액세스 할 수없는 경우 CFErrorRef 개체가 반환됩니다.

+0

여전히 메서드를 호출 할 때마다 동일한 문제가 발생하므로 null을 반환 할 것입니다. – Omarj

+0

CFErrorRef를 살펴 보셨습니까? –

+0

당신이 보는 것처럼 그것은 오류가 아니므로 로그를 남기거나 할 수 없습니다 & 오류가 발생했습니다. – Omarj

-1

지적한 바와 같이, @ 텔hel은 IOS6에서 ABAddressBookCreateWithOptions를 사용해야합니다. 경우 ([[[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 
} 

, GROUPSNAME 어딘가? 당신이 얻기를 위해 ABExternalChangeCallBack을 사용 .. 그 외에도에서

이된다 주소록 변경 알림?

연락처에 액세스하는 동일한 모듈 내에 그룹 코드를 넣어야한다고 생각합니다. (!이 도움이되지 않는 경우, 명확 않음)

+0

첫 번째로 나는 ABExternalChangeCallBack을 사용합니다. 그러면 사용자가 다음에 앱을 업데이트하면 알림을받을 때마다 충돌이 발생하지 않도록 10 시간을 더줍니다. 이것이 일어난다면 주소록에 다시 액세스하십시오. " 둘째 : 충돌이 발생하거나 나에게 아무 가치가없는 여러 번 물어 보면 연락처를 얻는 것과 같습니다. 그래서이 도움이되지 않습니다 : ( – Omarj

+1

원칙에 맞지 만, 시스템 버전의 floatValue를 가져 가기 위해 -1. API 가용성을 확인하는 것이 권장되는 방법이 아닙니다. –