-1

I am working on a chat application same as whatsapp. So I need same functionality when user disable/enable contact access (privacy setting) for my app. If the user disable or enable the contact in app setting. How can I be notify in the app. I need to keep track when user changes enable/disable contact settings (privacy setting). So i do reflect changes on each event in My App. And if anyone knows how whatsapp doing this.

Given below is the screenshots of whatsapp.

Case 1.Has Contact Access

whatsapp when has contacts access

Case 2 Don't Have Contact Access

enter image description here

Gagan Joshi
  • 3,347
  • 2
  • 21
  • 32

2 Answers2

1

Every time the user launch the app you can check if the app has still permission to the contacts with the following code:

  #import <AddressBookUI/AddressBookUI.h>


- (void)applicationWillEnterForeground:(UIApplication *)application {

  ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // First time access has been granted
         // Show 4 Tabs
      } else {
          // User denied access
          // Show 3 Tabs
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access, add the contact
    // Show 4 Tabs

  }
  else {
    // The user has denied access
    // Show only 3 Tabs
  }

}
Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36
  • Hi @Manuel, thanks for the quick response . I know about this. But I want to know if there is any delegate, notification or observer to notifiy App about authorization changes. – Gagan Joshi May 28 '15 at 12:28
  • 1
    Manuel -if you know how can i regenerate the pop up that your apps want to access your contact. I want to regenerate this. But that only comes once. if you know how to regenerate the pop up – Gagan Joshi May 28 '15 at 12:32
-1

As per apple's website (scroll down to Privacy in the middle of the page), access to the address book must be granted before it can be access programmatically.Here is what I ended up doing-

#import <AddressBookUI/AddressBookUI.h>

- (BOOL)isContactsFetchingAccessibleOrNot {
  // Request authorization to Address Book
  ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // First time access has been granted, add the contact
          //do something
      } else {
          // User denied access
          // Display an alert telling user the contact could not be added
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access, add the contact
    //do something
  }
  else {
    // The user has previously denied access
    // Send an alert telling user to change privacy setting in settings app
  }
}

You can also call this method when app comes from background to foreground.