IOS6.0 的settings/privacy/contacts没有出现自己的APP

来源:互联网 发布:java单例模式线程安全 编辑:程序博客网 时间:2024/04/29 06:19


在stack上找的答案:

That did the perfect trick for me!

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.

SOURCE: http://programmerjoe.blogspot.com/2012/10/ios6-permissions-contacts.html


第二点info.list里面有一项Privacy-Contacts Usage Description 加上去


oK,解决~

原创粉丝点击