2014-09-12 2 views
1

사람들이 iOS의 그룹에 쉽게 추가 및/또는 제거 할 수있는 기능을 앱에서 만들려고합니다. 그러나 내가 추가 및/또는 동시에 첫 번째 조치를 제거하기 위해 여러 사람을 선택하면 한 번 2)에 한 사람을 추가 iOS 주소록 그룹에 여러 사람 추가하기

1)

한 번에

을 한 사람을 제거 : 나는 경우 아래 코드는 완벽하게 작동 - 주소록에 추가가 없다면 먼저 추가하거나 제거합니다. 이 방법은 하나의 개별 작업으로 반복해서 호출 할 수 있으며 성공할 수 있습니다. 내가 저장/호출하는 단일 컨텍스트 내에서 여러 추가/삭제를 저장할 수없는 이유를 알 수 없다. 부울이 성공을 결정하는 데 사용 된 코드는 모든 오류가 발생하지 않고 완벽하게 작동한다는 것을 나타냅니다.

로컬 주소록 만들기, groupRef 검색, 각 for 루프 내 주소록 저장 등 다양한 조정 코드 조합을 시도했습니다. 또한 주소록을 소용 없게 저장 한 후 되돌릴 수 있는지 조사했습니다. 생각이나 경험?

-(IBAction)save:(id)sender 
{ 
    @synchronized(self) 
    { 
     CFErrorRef error = NULL; 
     BOOL success = NO; 
     BOOL successfulSave = NO; 

     ABAddressBookRef localAddressBook = ABAddressBookCreateWithOptions(NULL, &error); 
     group = ABAddressBookGetGroupWithRecordID(localAddressBook, groupID); 

     for (CFIndex addItemCount = 0; addItemCount < [theAddList count]; ++addItemCount) 
     { 
      NSNumber *addID = [theAddList objectAtIndex:addItemCount]; 
      ABRecordRef thePersonID = ABAddressBookGetPersonWithRecordID(localAddressBook, [addID intValue]); 
      success = success || ABGroupAddMember(group, thePersonID, &error); 
     } 

     for (CFIndex removeItemCount = 0; removeItemCount < [theRemoveList count]; ++removeItemCount) 
     { 
      NSNumber *removeID = [theRemoveList objectAtIndex:removeItemCount]; 
      ABRecordRef thePersonID = ABAddressBookGetPersonWithRecordID(localAddressBook, [removeID intValue]); 
      success = success || ABGroupRemoveMember(group, thePersonID, &error); 
     } 

     if (success) 
     { 
      successfulSave = ABAddressBookSave(localAddressBook, &error); 
     } 

     if (!(successfulSave && success)) 
     { 
      UIAlertView *addressBookUpdateAlert = [[UIAlertView alloc] initWithTitle:@"AddressBook Error" message:@"An update to your address book could not be processed at this time. Try again shortly." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
      // we can't update a GUI element from a background thread - appears sensitivity didn't appear until iOS 8 
      [[NSOperationQueue mainQueue] addOperationWithBlock: 
      ^{ 
       [addressBookUpdateAlert show]; 
      }]; 
     } 
     else 
     { 
      [[self navigationController] popViewControllerAnimated:YES]; 
     } 
    } 
} 

답변

0

나는 그것을 설명 할 수 없다,하지만 오류를 트래핑의 더 나은 일을 대신 마술 작업을 시작하는 코드에 의한 것으로 보인다해야 작은 변화를 만들어 - 일반적으로 코드 그런데 어느 너를 위해 너는 어딘가에서 기억을 썼다.

어쨌든 나는 다음을했고,이 일을 시작 :

  1. 설정 성공 = YES 루프
  2. 를 입력하기 전에를 변경 || 모두의 & & 테스트에 테스트

모든 I가 변경 아직 어떻게 든 그냥 일을 시작 루프 ... 이상한 ... 내가 시험에 떨어져있어/내가 일을보고 있어요 경우에 일을 망치. ..

관련 문제