顯示具有 privacy 標籤的文章。 顯示所有文章
顯示具有 privacy 標籤的文章。 顯示所有文章

2012年10月15日 星期一

[iOS] Why no privacy alerts in simulator?

This is not a bug. This is the restriction on simulator.
From the iOS6.0 release note, we seen that apple doesn't the privacy alerts in simulator.

Simulator

  • No privacy alerts are displayed in iOS Simulator for apps that access Photos, Contacts, Calendar, and Reminders.
  • For this release, iOS Simulator does not support testing In-App Purchase. Please use a device to test your apps that use this feature.
  • When attempting to play an MP3 sound in Simulator, you will hear a popping sound instead.
Source:iOS6.0 release note

Reset iPhone Privacy

To clear/reset iPhone Privacy Settings like contacts and location services, you can go to Settings and follow the routine:
Settings -> General -> Reset -> Reset Privacy and Location

Which is useful for developer, as the privacy prompt only prompt once if you never reset.

2012年10月14日 星期日

Toggling Privacy settings in iOS6 will kill the app

If you played with Location Services in iPhone, you knows that after you changed the location setting in iPhone Settings, you are able to get the change and update your application. While Contact(AddressBook) and Location Services are both packed in Privacy Setting, you would expect there is similar behaviour on Contact.

Sadly, its not true. After you changed the setting of contact, your app will receive a SIGKILL signal and stop.

Source:StackOverflow

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.