IPhone application development ABAddressBook related API usage experience

Source: Internet
Author: User

IPhone applicationsDevelopmentABAddressBookRelated API usage experience is described in this article. it is very rare to sum up the knowledge of various problems and solutions encountered during the ABAddressBook address book operation during iPhone application development. I recently studied this and submitted a program. The reject is used because the following code is used.

1. mABPersonViewController = [ABPersonViewController alloc] init];

2. [mABPersonViewController setAllowsDeletion: YES];

So I researched and implemented the same function, and found that there was a problem in the API ......

Memorandum:

1. Do not pass ABRecordRef. Always use RecordID. For example, the following code

 
 
  1. ABRecordRef recordRef = ABAddressBookGetPersonWithRecordID(addressBookRef,ABRecordGetRecordID([mPersonViewController displayedPerson])); 

You will find that the addresses of recordRef and [mPersonViewController displayedPerson] are not necessarily the same. Here, mPersonViewController is an instance of any ABPersonViewController. addressBookRef is a copy of the AddressBook you are operating on. Because they come from different AddressBook replicas, different addresses cannot be used together.

2. ABAddressBookHasUnsavedChanges. This function is useless and always returns NO. After searching google for a long time, I found that this function was originally invalid. This problem still exists in iPhone OS 2.x and later versions.

3. Another bug is that even if setAllowsDeletion: YES is not used, you can still see the Delete contact button when using the following code.

 
 
  1. - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
  2. shouldContinueAfterSelectingPerson:(ABRecordRef)person{  
  3.         [personViewController setDisplayedPerson:person];  
  4.        [personViewController setEditing:YES];  
  5.         [peoplePicker pushViewController:personViewController animated:YES];  
  6.     }  
  7.    return NO;  

After executing the code above, the contact details page is displayed, which is an editing page, with the delete button at the bottom ...... However, this effect cannot be achieved through any other method. For example, when you click the "edit" button, set the current ABPersonViewController to setEditing: YES, and there is no delete button ......

Problem:

Because ABAddressBookHasUnsavedChanges always returns NO, I can determine whether the address book is modified by checking whether ABAddressBookRemoveRecord returns YES. If yes, directly ABAddressBookSave.

However, sometimes the following error occurs, and the search result for this keyword in google is 0.

 
 
  1. sqlite3 error in CPRecordStoreSaveWithPreAndPostCallbacksAndTransactionType: cannot commit - no transaction is active 

Later, I tried the illegal Code mentioned below. After testing, I found that this error message was also displayed when I used the official "Delete contact" button ...... So I wondered ...... I don't know how everyone solves this problem?

1. mABPersonViewController = [ABPersonViewController alloc] init];

2. [mABPersonViewController setAllowsDeletion: YES];

In addition, to prevent the entire address book from being lost, the rule I have summarized is:
 
1. You must always use the same AddressBook copy. That is to say, the operated ABAddressBookRef address is the same. Avoid creating more copies, and sometimes the entire database may be lost when you exit the program ......

2. When using multiple threads to operate the same AddressBook copy, you must avoid simultaneous operations.

Summary:IPhone applicationsDevelopmentABAddressBookThe related API experience has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.