Abaddressbooksave about the failure of saving to address book

First of all, the premise is that you add the address book statement without any errors.
And then there is
// Add the newly created contact to the address book
ABAddressBookAddRecord (addressBook, person, NULL);
The next step is to save the address book in order to better learn how to deal with the Error that will not cause crashes and prompts. It is recommended that you create an Error object to see the Error prompts given by the system

CFErrorRef error = NULL;
If (ABAddressBookSave (addressBook, & amp; error))
UIAlertView * Alert = [[UIAlertView Alloc] initWithTitle:@” prompt “Message :@” has successfully imported contacts into address book” delegate: Self cancelButtonTitle:@” confirm “otherButtonTitles:nil];
[alert show];
The else
NSLog (@ “% @”, the error).
UIAlertView * Alert = [[UIAlertView Alloc] initWithTitle: @@” prompt “message:@” import failed” delegate:self cancelButtonTitle:@” confirm “otherButtonTitles:nil];
[alert show];

The error is “error Domain=ABAddressBookErrorDomain Code=1 “The operation couldn’t be completed. (ABAddressBookErrorDomain error 1.)”

This error basically means that the operation is not complete, which does nothing to me, but at least it tells us one thing, that there is nothing wrong with the code we write. If there’s nothing wrong with the code, why did it fail to save the contact to the address book?The only answer seems to be that the system won’t allow you to access the address book
Solution: First in the phone’s privacy Settings, address book privacy to see if the permissions are turned on.
It then gives a code to request application access to the address book before importing.

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion (addressBook, ^ (bool granted, CFErrorRef error) {
The first time, a prompt will pop up telling the user whether to allow the application to access the address book
Else if (ABAddressBookGetAuthorizationStatus () = = kABAuthorizationStatusAuthorized) {
Description accessible
The else {
The user may have turned off access to the communication.

Well, the problem with the address book not being able to hold data has finally been solved.

Read More: