2012-12-18 3 views
0

내가 데이터베이스에 ABPropertyID를 저장하고에 나는 상대가 연락처에서 삭제 내가 ABRecordRef를 얻을려고하지만, 응용 프로그램입니다 충돌 ABAddressBookGetPersonWithRecordID(addressBook, recordID).으로 ABRecordRef의 수를 표시 한 기반으로 한 응용 프로그램 분명한.ABAddressBookGetPersonWithRecordID 충돌 내 응용 프로그램에서 recordId를 사용할 수 없습니다

그래서 제 질문은 : recordID와는 주소록에 사용할 수 있는지 확인할 수있는 방법이

있습니까?

답변

0

먼저 유 whther null의 여부를 확인해야한다,이

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL); 

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { 
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) { 
     // First time access has been granted, add the contact 
     ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL); 

     ABRecordRef newPerson = ABPersonCreate(); 

     ABRecordSetValue(newPerson, kABPersonSortByFirstName,(__bridge CFTypeRef)(firstname),&error); 
     ABRecordSetValue(newPerson, kABPersonLastNameProperty,(__bridge CFTypeRef)(lastname), &error); 
     ABRecordSetValue(newPerson, kABPersonOrganizationProperty, @"", &error); 
     ABRecordSetValue(newPerson, kABPersonJobTitleProperty,@"", &error); 



     ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
     ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(contact_phone), kABPersonPhoneMainLabel, NULL); 
     ABMultiValueAddValueAndLabel(multiPhone, @"", kABPersonPhoneMobileLabel, NULL); 
     ABMultiValueAddValueAndLabel(multiPhone, @"", kABOtherLabel, NULL); 
     ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil); 
     CFRelease(multiPhone); 



     ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
     ABMultiValueAddValueAndLabel(multiEmail,(__bridge CFTypeRef)(contact_email) , kABWorkLabel, NULL); 
     ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error); 
     CFRelease(multiEmail); 

     //  ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 
     // NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init]; 
     // [addressDictionary setObject:@"750 North Orleans Street, Ste 601" forKey:(NSString *) kABPersonAddressStreetKey]; 
     // [addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey]; 
     // [addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey]; 
     // [addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey]; 
     // ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL); 
     // ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error); 
     // CFRelease(multiAddress); 

     ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error); 
     ABAddressBookSave(iPhoneAddressBook, &error); 

     if (error != NULL) 
     { 
      NSLog(@"Danger Will Robinson! Danger!"); 
     } 


     // ABAddressBookRef addressBook = ABAddressBookCreate(); 


    }); 
} 
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { 
    CFErrorRef error = NULL; 
    // ABAddressBookRef addressBook =ABAddressBookCreateWithOptions(NULL, NULL); 

    ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL); 

    ABRecordRef newPerson = ABPersonCreate(); 

    ABRecordSetValue(newPerson, kABPersonSortByFirstName,(__bridge CFTypeRef)(firstname),&error); 
    NSLog(@"%@",(__bridge CFTypeRef)(firstname)); 
    ABRecordSetValue(newPerson, kABPersonLastNameProperty,(__bridge CFTypeRef)(lastname), &error); 
    NSLog(@"%@",(__bridge CFTypeRef)(lastname)); 

    ABRecordSetValue(newPerson, kABPersonOrganizationProperty, @"", &error); 
    ABRecordSetValue(newPerson, kABPersonJobTitleProperty,@"", &error); 

    ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
    ABMultiValueAddValueAndLabel(multiPhone,(__bridge CFTypeRef)(contact_phone), kABPersonPhoneMainLabel, NULL); 
    ABMultiValueAddValueAndLabel(multiPhone, @"", kABPersonPhoneMobileLabel, NULL); 
    ABMultiValueAddValueAndLabel(multiPhone, @"", kABOtherLabel, NULL); 
    ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil); 
    CFRelease(multiPhone); 



    ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
    ABMultiValueAddValueAndLabel(multiEmail, (__bridge CFTypeRef)(contact_email), kABWorkLabel, NULL); 
    ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error); 
    CFRelease(multiEmail); 

    //  ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 
    // NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init]; 
    // [addressDictionary setObject:@"750 North Orleans Street, Ste 601" forKey:(NSString *) kABPersonAddressStreetKey]; 
    // [addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey]; 
    // [addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey]; 
    // [addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey]; 
    // ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL); 
    // ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error); 
    // CFRelease(multiAddress); 



    ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error); 
    ABAddressBookSave(iPhoneAddressBook, &error); 
    alertvalue++; 

    if (error != NULL) 
    { 
     NSLog(@"Error not found!"); 
    } 


    // ABAddressBookRef addressBook = ABAddressBookCreate(); 


} 
else { 
    // The user has previously denied access 
    // Send an alert telling user to change privacy setting in settings app 
}  } 
+0

를 시도? 다음을 추가하십시오 –

관련 문제