Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ask for permission to allow access to Contacts iOS [duplicate]

I am importing all the native address book contacts into my app. Currently, the alertview to ask for permission to 'allow access to the Contacts' is done at the launch of the app.

How do I change it so permission is asked elsewhere in the app? At the click of a button, just like Instagram?

See this picture:

enter image description here

like image 815
Hassan Avatar asked Oct 12 '13 18:10

Hassan


People also ask

How do I fix duplicate contacts in iOS?

Resolve duplicate contacts If you have more than one contact card with the same first and last name, you can merge the duplicate contacts. Below My Card, tap Duplicates Found. Tap individual contacts to review and merge them, or tap Merge All to merge all duplicate contacts.

Why does my iPhone contacts keep duplicating?

These duplicates can occur when you have multiple spellings of the same name or email address, or when you imported your contacts to Outlook. You must delete duplicate contacts manually, or you can merge them by changing the information from one contact to match the information from the duplicate.

How do I get iPhone to stop asking for permission?

On your iPhone, iPad, or iPod touchTap Family Sharing. Tap Ask to Buy. Tap your family member's name. Use the toggle to turn on or turn off Ask to Buy.

How do I fix duplicate contacts?

On your Android phone or tablet, open the Contacts app . At the top right, select the Google Account that has the duplicate contacts you want to merge. At the bottom, tap Fix & manage Merge & fix. Tap Merge duplicates.


1 Answers

You can read the documentation HERE.

Here is some code to get you started:

//First of all import the AddRessBookUI 
  #import <AddressBookUI/AddressBookUI.h>

  // Request to authorise the app to use addressbook
  ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(nil, nil);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // If the app is authorized to access the first time then add the contact
          [self _addContactToAddressBook];
      } else {
          // Show an alert here if user denies access telling that the contact cannot be added because you didn't allow it to access the contacts
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // If the user user has earlier provided the access, then add the contact
    [self _addContactToAddressBook];
  }
  else {
    // If the user user has NOT earlier provided the access, create an alert to tell the user to go to Settings app and allow access
  }

Here are another couple of tutorials that you might like to see that you can find HERE and HERE.

Hope this helps!

UPDATE: You have to use didFinishLaunchingWithOptions to detect the first time your app launches:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        // The app has already launched once
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first time the app is launched
    }
}
like image 199
AJ112 Avatar answered Sep 30 '22 20:09

AJ112