2012年10月8日 星期一

iOS6 permissions [Contacts]

On iOS6, apple introduce new privacy control, user can control the accessment of contact and calender by each app. So, in the code side, you need to add some way to request the permission. In iOS5 or before, we can always call
ABAddressBookRef addressBook = ABAddressBookCreate();
to get the addressbook without any problem, but in iOS6, if you don't have permission, this call will just return empty pointer. That why we need to change the method to get ABAddressBookRef.

__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);  
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // Do whatever you want here.
}
In the code,semaphore is used for blocking until response, while ABAddressBookRequestAccessWithCompletion will ask for permission if the app didn't ask before. Otherwise it will just follow the settings in Settings-Privacy-Contact.

13 則留言:

  1. Thanks .It helped me a lot.

    回覆刪除
  2. Nice & Informative Blog !
    If you are looking for the best accounting software that can help you manage your business operations. call us at QuickBooks Customer Service Number 1-855-974-6537.

    回覆刪除
  3. Hey! Amazing work. With full of knowledge. Our Team resolve any glitches occurring while utilizing the software. Looking Quickbooks For Mac Support Phone Number 1-855-756-1077. Our experts will assist you to fulfil your accounting needs. The solutions are accurate and time-saving.

    回覆刪除
  4. Nice Blog !
    At times, while filing form 941, you may face QuickBooks Form 941 Error when the total sum of the tax amount exceeds $2500. To fix such issue, you must contact our experts via QuickBooks Support Number and get permanent ways to solve QuickBooks problems.

    回覆刪除
  5. Quality is our priority. And we do everything to achieve that such as choosing suitable essay assignment writer for the job, conveying customers’ suggestions to the writer, setting up a quality management team, etc. This way, we ensure that all our customers receive highest quality essay assignment assistance from us.
    http://www.dissertationhomework.com

    回覆刪除
  6. Best content & valuable as well. Thanks for sharing this content.
    Approved Auditor in DAFZA
    Approved Auditor in RAKEZ
    Approved Auditor in JAFZA
    i heard about this blog & get actually whatever i was finding. Nice post love to read this blog
    Approved Auditor in DMCC

    回覆刪除
  7. thank you for providing us this useful information do Busines with Intwiff

    回覆刪除
  8. Hey! Mind-blowing blog. Keep writing such beautiful blogs. In case you are struggling with issues on QuickBooks software, dial QuickBooks Customer Service Phone Number . The team, on the other end, will assist you with the best technical services.

    回覆刪除
  9. wordpress design agency in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!

    回覆刪除